Struts2中集合收集表单数据

Posted HelloWorld1815

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Struts2中集合收集表单数据相关的知识,希望对你有一定的参考价值。

收集表单的页面:

 1 <form action="listAction1!insert" method="post">
 2         dog1:<input name="ulist[0].dog.did"/>
 3             <input name="ulist[0].dog.dname"/><br>
 4         dog2:<input name="ulist[1].dog.did"/>
 5             <input name="ulist[1].dog.dname"/><br>
 6         dog3:<input name="ulist[2].dog.did"/>
 7             <input name="ulist[2].dog.dname"/><br>
 8         dog4:<input name="ulist[3].dog.did"/>
 9             <input name="ulist[3].dog.dname"/><br>
10         dog5:<input name="ulist[4].dog.did"/>
11             <input name="ulist[4].dog.dname"/><br>
12         dog6:<input name="ulist[5].dog.did"/>
13             <input name="ulist[5].dog.dname"/><br>
14             <input type="submit" value="提交"/>
15     </form>

 struts.xml里:

<action name="listAction1" class="com.xsl.action.ListAction1">
  <result name="success">/success.jsp</result>
</action>

ListAction1.java里:

 1 package com.xsl.action;
 2 
 3 import java.util.ArrayList;
 4 import java.util.List;
 5 
 6 import javax.servlet.http.HttpServletRequest;
 7 
 8 import org.apache.struts2.interceptor.ServletRequestAware;
 9 
10 import com.opensymphony.xwork2.ActionSupport;
11 import com.xsl.entity.Dog;
12 import com.xsl.entity.Users;
13 
14 public class ListAction1 extends ActionSupport implements ServletRequestAware {
15     private Users users;
16     private HttpServletRequest request;
17     private List<Users> ulist;
18     public String insert(){
19         for(Users u:ulist){
20             System.out.println(u.getDog().getDid()+"---"+u.getDog().getDname());
21         }
22         return SUCCESS;
23     }
24     public void setServletRequest(HttpServletRequest request) {
25         this.request = request;
26     }
27     public Users getUsers() {
28         return users;
29     }
30     public void setUsers(Users users) {
31         this.users = users;
32     }
33     public HttpServletRequest getRequest() {
34         return request;
35     }
36     public void setRequest(HttpServletRequest request) {
37         this.request = request;
38     }
39     public List<Users> getUlist() {
40         return ulist;
41     }
42     public void setUlist(List<Users> ulist) {
43         this.ulist = ulist;
44     }
45 }

 



以上是关于Struts2中集合收集表单数据的主要内容,如果未能解决你的问题,请参考以下文章

js怎么获取集合中集合的数据(集合中的一个参数是集合)

为 Symfony 2 中集合的每个项目指定不同的验证组?

如何确定 Python 中集合变量的大小?

Hive中集合类型

什么决定了这个 python 3 代码中集合元素的顺序? [复制]

JAVA中集合转数组遍历