1.1.1    Struts2中封装复杂类型的数据:

封装到List集合:

页面:

商品名称:<input type="text" name="products[0].pname"/><br/>

商品价格:<input type="text" name="products[0].price"/><br/>

商品名称:<input type="text" name="products[1].pname"/><br/>

商品价格:<input type="text" name="products[1].price"/><br/>

商品名称:<input type="text" name="products[2].pname"/><br/>

商品价格:<input type="text" name="products[2].price"/><br/>

Action:

public class ProductAction1 extends ActionSupport{

private List<Product> products;

public List<Product> getProducts() {

return products;

}

public void setProducts(List<Product> products) {

this.products = products;

}

}

封装到Map集合

页面:

商品名称:<input type="text" name="map['one'].pname"/><br/>

商品价格:<input type="text" name="map['one'].price"/><br/>

商品名称:<input type="text" name="map['two'].pname"/><br/>

商品价格:<input type="text" name="map['two'].price"/><br/>

商品名称:<input type="text" name="map['three'].pname"/><br/>

商品价格:<input type="text" name="map['three'].price"/><br/>

Action:

public class ProductAction2 extends ActionSupport{

private Map<String,Product> map;

public Map<String, Product> getMap() {

return map;

}

public void setMap(Map<String, Product> map) {

this.map = map;

}

}

struts2 复杂参数封装的更多相关文章

  1. (八)Struts2中的参数封装

    一.静态参数封装 什么是静态参数? 静态参数就是硬编码的,不可随意改变. 例子: (1)我们首先创建一个Action类,里面有两个参数,用来封装请求参数 public class User exten ...

  2. struts2 二: 参数封装

    封装请求正文到对象中(非常重要) 1.静态参数封装 在struts.xml配置文件中,给动作类注入值.调用的是setter方法. struts.xml的编写: <action name=&quo ...

  3. Struts2(二)之封装请求正文、数据类型转换、数据验证

    一.封装请求正文到对象中(重点) 1.1.静态参数封装 在struts.xml文件中,给动作类注入值,使用的是setter方法 1.2.动态参数封装 通过用户表单封装请求正文参数 1.2.1.动作类作 ...

  4. Struts2获取参数的几种方式

    Struts2由于是一个贴心的框架,所以获取参数这种体力活,就无需再通过原生的request来getParameter了,有如下几种方式进行获取 1.Action中属性驱动,必须提供与form表单na ...

  5. Struts 2.3.24源码解析+Struts2拦截参数,处理请求,返回到前台过程详析

    Struts2官网:http://struts.apache.org/ 目前最新版本:Struts 2.3.24 Struts1已经完全被淘汰了,而Struts2是借鉴了webwork的设计理念而设计 ...

  6. Struts2接受参数的几种类型和接受复杂类型参数(list<String>和list<Object>)

    Struts2接受参数的几种类型 大概有这几种类型: 1.使用Action的属性接受参数 在Action中加入成员变量,配置Getter和Setter方法,Getter而和Setter方法的名字和表单 ...

  7. 在jsp提交表单的参数封装到一个方法里

    建议去看一下孤傲苍狼写的Servlet+JSP+JavaBean开发模式(http://www.cnblogs.com/xdp-gacl/p/3902537.html), 最好把他JavaWeb学习总 ...

  8. 通过反射将request中的参数封装到对象中

    import java.beans.PropertyDescriptor; import java.lang.reflect.Method; import java.text.SimpleDateFo ...

  9. Spring MVC参数封装传递

    在Spring MVC中,前端JSP页面可以传递  基本类型(int,String).实体类型.包装类型.数组类型.集合类型(List.map )等. 假如在传递的类型中有 Date类型的字段,需要在 ...

随机推荐

  1. RabbitMQ service is already present - only updating service parameters

    如果你安装RabbitMQ不是那么一番顺利..那么你有可能会重装多次.. So..问题来了..重装时你执行   rabbitmq-service install  的时候..有可能就会报这个错了.. ...

  2. jquery 中的事件冒泡

    废话少说,先来一段代码热热身: <!DOCTYPE html> <html> <head> <title>demo</title> < ...

  3. firefox 提示 setTimeout():useless setTimeout call (missing quotes around argument?) 错误

    原来代码: setTimeout(window.parent.refreshNode(id),500);// 500毫秒后,调用父窗口的refreshNode()方法 refreshNode()方法总 ...

  4. 我再也不-或许永远不-用zend studio-受够了!

    zend studio背负的东西太多, 想要整合php, js, aptana, emmet, 还要git, 所以显得很累. 不过把这些它整合的东西 都用上后, 用好后, 倒确实是php的开发利器. ...

  5. hdu4951 Multiplication table (乘法表的奥秘)

    http://acm.hdu.edu.cn/showproblem.php?pid=4951 2014多校 第八题 1008 2014 Multi-University Training Contes ...

  6. dedecms数据库表前缀不一样怎么还原数据

    我们在用dedecms建站时,安装一般都“下一步”直接往下点,这样默认的表前缀是dede_,如果我们要还原从其他地方拷贝过来的数据,一定要注意表头是否一致.如果表头不一样怎么办呢?有两种方法,第一种, ...

  7. HTMLDOM中三种元素节点、属性节点、文本节点的测试案例

    HTML dom中常用的三种节点分别是元素节点.属性节点.文本节点. 具体指的内容可参考下图: 以下为测试用例: <!DOCTYPE html> <html> <head ...

  8. C++ GET UTF-8网页编码转换

    string UTF8ToGBK(const std::string& strUTF8)                                //GBKתUTF-8 { int le ...

  9. Lua模块测试

    Lua模块 ---------------------------------------------------------- ----------------------- 模块测试module_ ...

  10. Jrebel是一套开发环境,用来实现热部署

    http://truemylife.iteye.com/blog/1140921 背景与愿景:开发环境下,tomcat对热布署的支持还不够全面,致使开发人员浪费大量时间在重起服务上.为了提高开发效率, ...