怎样在struts2中完整遍历list

摸鱼童子 2017-09-21 09:20:29
public class UserAction extends ActionSupport{

private User user;

private List<User> userList;
private List<User> dbList= new ArrayList<User>();


public String saveUser() {
System.out.println(user.getUsername());
System.out.println(user.getEducationList().get(0).getSchool());
System.out.println(user.getSex());
System.out.println("--------");

HttpServletRequest request = ServletActionContext.getRequest();
HttpSession session = request.getSession();

dbList.add(user);

System.out.println(dbList.size());
for(User u : dbList){
System.out.println(u.getUsername());
}

return "success";
}

public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}

前台:
<body>
部门管理>>添加员工<br>
<form action="saveUserAction" method="post">
姓名:<input type="text" name="user.username"><br>
年龄:<input type="text" name="user.age"><br>
性别:<input type="text" name="user.sex"><br>
教育背景<br>
<table border="1px">
<tr>
<td>起始年份</td>
<td>结束年份</td>
<td>教育机构</td>
<td>所获学历</td>
</tr>

<tr>
<td><input type="text" name="user.educationList[0].beginYear"/></td>
<td><input type="text" name="user.educationList[0].endYear"/></td>
<td><input type="text" name="user.educationList[0].school"/></td>
<td><input type="text" name="user.educationList[0].grade"/></td>
</tr>

<tr>
<td><input type="text" name="user.educationList[1].beginYear"/></td>
<td><input type="text" name="user.educationList[1].endYear"/></td>
<td><input type="text" name="user.educationList[1].school"/></td>
<td><input type="text" name="user.educationList[1].grade"/></td>
</tr>

<tr>
<td><input type="text" name="user.educationList[2].beginYear"/></td>
<td><input type="text" name="user.educationList[2].endYear"/></td>
<td><input type="text" name="user.educationList[2].school"/></td>
<td><input type="text" name="user.educationList[2].grade"/></td>
</tr>

</table>
<input type="submit" value="提交">
</form>
</body>

每次测试打印的结果
--------
1
tom2
为什么之前提交的数据没有存到list里面?怎么用session来解决?
...全文
1158 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

8,906

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧