输出request里保存的List

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)