Struts2的iterator标签遍历Map
2013-04-16 20:10
344 查看
Struts2的iterator标签遍历Map
一,struts.xml
<package name="express" extends="struts-default" namespace="/exp"> <action name="expressMap" class="com.testmap.action.MapAction"> <result name="result">/jsp/strMap.jsp</result> </action> </package>
二、JavaBean类
1、Person.javapublic class Person { private String name; private String ID; private int age; private Phone phone; Person(String name, String ID,int age) { this.name = name; this.ID= ID; this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public Phone getPhone() { return phone; } public void setPhone(Phone phone) { this.phone = phone; } public String getID() { return ID; } public void setID(String iD) { ID = iD; } }
2、Phone.java
package com.testmap.action; public class Phone { private String name; private long xuhao; Phone(String name, long xuhao) { this.name = name; this.xuhao = xuhao; } public String getName() { return name; } public void setName(String name) { this.name = name; } public long getXuhao() { return xuhao; } public void setXuhao(long xuhao) { this.xuhao = xuhao; } }
3、MapAction.java
package com.testmap.action; import com.opensymphony.xwork2.ActionSupport; public class MapAction extends ActionSupport{ private Map<Person, List<Phone>> ppmap = new HashMap<Person, List<Phone>>(); @Override public String execute() throws Exception { List<Phone> phones = new ArrayList<Phone>(); phones.add(new Phone("Htc", 12345677L)); phones.add(new Phone("apple", 987654321L)); Person p = new Person("xiaoming", "bala", 21); ppmap.put(p, phones); return "result"; } public Map<Person, List<Phone>> getPpmap() { return ppmap; } public void setPpmap(Map<Person, List<Phone>> ppmap) { this.ppmap = ppmap; } }
三、jsp页面
strMap.jsp<div align="center"> <s:iterator value="ppmap.keySet()" var="key"> <s:property value="#key.ID" /> <s:property value="#key.name" /> <s:property value="#key.age" /><p> <s:iterator value="ppmap.get(#key)" var="ph"> <s:property value="#ph.name" /> <s:property value="#ph.xuhao" /><p> </s:iterator> </s:iterator> </div>
相关文章推荐
- Struts2中iterator标签遍历map总结
- Struts2中iterator标签遍历map总结
- Struts2中iterator标签遍历map总结(转)
- Struts2中iterator标签遍历map总结
- Struts2中iterator标签遍历map总结
- 使用Struts2的iterator标签遍历复杂的Map类型
- 使用Struts2的iterator标签遍历复杂的Map类型
- Struts2中iterator标签遍历map总结
- struts2 action 前端 iterator 标签遍历 map, list, array 数组
- 使用Struts2的iterator标签遍历复杂Map种类
- Struts2中iterator标签遍历map总结(转)
- Struts2中iterator标签遍历map总结
- Struts2中iterator标签遍历map总结
- Struts2中iterator标签遍历map总结
- Struts2中iterator标签遍历map总结
- Struts2中iterator标签遍历map总结
- Struts2 iterator 标签遍历 Map,List,数组
- Struts2中iterator标签遍历map总结
- Struts2中iterator标签遍历map总结
- Struts2中iterator标签遍历map总结