struts2怎样遍历list的全部数据

摸鱼童子 2017-09-21 01:08:33
action:
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";
}
前台:
<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
tom1
list里面只有一组数据,之前提交的就显示不出来。我知道是每次都new了一个新的list但是怎么用session改呢?求大神解答!
...全文
1145 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
lifewell1 2017-09-21
  • 打赏
  • 举报
回复
使用C标签 <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <c:forEach items="${sysUser.moduleList}" var="module"> </c:forEach>

8,906

社区成员

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

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