(6)选择标签与迭代标签

public String show() {
	this.setUsername("HZP");
	this.setPassword("HZP123");
	ActionContext.getContext().put("age", 80);
	List users=new ArrayList<>();
	users.add(new User("HZP1", "p1"));
	users.add(new User("HZP2", "p2"));
	users.add(new User("HZP3", "p3"));
	users.add(new User("HZP4", "p4"));
	ActionContext.getContext().put("users", users);
	return "success";
}
<%@ taglib prefix="s" uri="/struts-tags" %>



Insert title here


show

未成年 成年人 老年人
//迭代方式1: --------
//迭代方式2:
style="background:#ff0"> --------

CompoundRoot:是一个使用list的栈结构

迭代方式1:当使用迭代标签后,会将相应的users中的每一个对象(tempUser)放到CompoundRoot中{入栈},此时id相当于#root[0].id,该对象使用完毕后,出栈,然后users中的下一个对象入栈,反复执行。

迭代方式2当定义var=“u”时,就会将users中的每一个对象存在ActionContext中,当循环完成后,ActionContext中该对象也会清空,因为在ActionContext中,所以使用#u.id等取数据(注意加#)

你可能感兴趣的:(struts,Struts)