欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

输出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>

 

相关标签: JSP