输出request里保存的List
程序员文章站
2022-03-15 15:03:08
...
User类
private Integer id ;
private String username ;
private String password ;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
execute方法
public String execute() throws Exception {
List<User> list = new ArrayList<User>();
for (int i = 1; i <= 5; i++) {
User user = new User();
user.setId(i);
user.setUsername("username" + i);
user.setPassword("password" + i);
list.add(user);
}
HttpServletRequest request = ServletActionContext.getRequest();
request.setAttribute("list", list);
return SUCCESS;
}
jsp中使用<s:iterator>标签迭代输出list里面保存的User
<table border="1">
<s:iterator value="#request.list">
<tr>
<td><s:property value="id"/></td>
<td><s:property value="username"/></td>
<td><s:property value="password"/></td>
</tr>
</s:iterator>
</table>
上一篇: struts2拦截器
下一篇: POI实现导出Excel数据工具类
推荐阅读