struts2怎样遍历list的全部数据

摸鱼童子 摸鱼童子 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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改呢?求大神解答!
...全文

相关推荐

评论 1
收藏 已收藏
分享
返回顶部
摸鱼童子
XML/XSL 8,906 成员 22,677 内容