struts2 复杂参数封装

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;

}

}

时间: 2024-07-30 13:52:46

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

structs2 jsp页面参数封装成类传递到action

中途切入一个系统的维护,而我又是菜鸟. 系统要实现从前端jsp页面输入查询条件,传入后台action进行处理.根据原来的系统本身的代码大概明白是jsp里ognl表达式传参数过去,但是一直不成功.百度各种办法,找到下面方法都试过,好像都不行.找耳挠腮搞半天才发现,我ognl表达式里的值得大小写和action里的类实例名不一致,真是不能更二咯-.- 对齐了jsp里的ognl表达式和action里的类实例名后,问题解决了.把我搜到的structs2 jsp传参数到后台action的方法记录下来,抄一遍

Struts2接受参数的几种类型和接受复杂类型参数(list&lt;String&gt;和list&lt;Object&gt;)

Struts2接受参数的几种类型 大概有这几种类型: 1.使用Action的属性接受参数 在Action中加入成员变量,配置Getter和Setter方法,Getter而和Setter方法的名字和表单中input标签的name属性一致(简单来说就是Action中变量的名和表单中input的name值一致) 2.使用DomainModel接收参数 JSP: <form action="LoginAction.action" method="post"> U

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

建议去看一下孤傲苍狼写的Servlet+JSP+JavaBean开发模式(http://www.cnblogs.com/xdp-gacl/p/3902537.html), 最好把他JavaWeb学习总结全部看完会有很大的收获哦! 而把jsp专递的参数封装到一个方法里面也是从他那里学到的. 我觉得特别有用,尤其是在做项目的时候能省很多的代码  一: 需要的包 根据上一篇JDBC+Servlet+jsp(http://www.cnblogs.com/zhu520/p/6913650.html)的内容

SpringMVC 中,当前台传入多个参数时,可将参数封装成一个bean类

在实际业务场景中,当前台通过 url 向后台传送多个参数时,可以将参数封装成一个bean类,在bean类中对各个参数进行非空,默认值等的设置. 前台 url ,想后台传送两个参数,userName 和 password: 1 http://localhost:8082/web/baseAction.do?pathVar=app/task/fetchItemDetail.do?userName=123&password=123 将参数封装成bean 类,并在bean类中对参数进行控制: 1 2 3

Struts2请求参数校验

校验的分类 客户端数据校验 和 服务器端数据校验 客户端数据校验 ,通过JavaScript 完成校验 (改善用户体验,使用户减少出错 ) 服务器数据校验 ,通过Java代码 完成校验 struts2 支持校验方式 代码校验(用的很少) :在服务器端通过编写java代码,完成数据校验 配置校验(主流):XML配置校验(主流) 和 注解配置校验 代码校验请求参数 步骤一: 封装数据 步骤二: 实现校验Action ,必须继承ActionSupport 类 步骤三: 覆盖validate方法(val

struts2 请求参数接收

1. 采用基本类型接受请求参数(get/post)在Action类中定义与请求参数同名的属性,struts2便能自动接收请求参数并赋予给同名的属性.请求路径:http://localhost:8080/action/register.action?id=33 public class HelloWorldAction { private Integer id; public Integer getId() { return id; } public void setId(Integer id)

struts2接收参数

struts2有三种接收参数的方式: 1.Action属性 2.Domain Model 3.ModelDriven login.jsp页面: <body>   <form action="loginAction.action" method="post" > 用户名:<input type="text" name="username"/> 密码:<input type="p

Struts2请求参数合法性校验机制

在Action中通过代码执行数据校验 请求参数的输入校验途径一般分两种:客户端校验 :通过JavaScript 完成 (jquery validation插件),目的:过滤正常用户的误操作. 服务器校验 :通过java代码完成 ,目的:整个应用阻止非法数据的最后防线 列如: <h1>登录:请求数据校验--代码手动校验</h1> <s:fielderror/> <form action="${pageContext.request.contextPath

struts2关于参数

关于struts2的参数传递 1. 通过属性 userName passWorld getXX() setXX() 2. 数组 String[] str; getXX() setXX() 3. 对象 User user; setXX() getXX() 4. 集合 List<User> user; setXX()  getXX() 如图 1.通过属性 private String userName; private String passWorld; public String getUser