The first structure of map<k,<list<xxx>>>
<Body> <%//Show Map<string,list<object>> Map map = new HashMap<String, List<string>> (); List List = new ArrayList<String>(); List.add ("List1-1"); List.add ("List1-2"); List.add ("List1-3"); List list2 = new ArrayList<String>(); List2.add ("list2-1"); List2.add ("list2-2"); List2.add ("list2-3"); Map.put ("A", list); Map.put ("B", List2); Actioncontext.getcontext (). Getvaluestack (). Request.setattribute ("Map1", map); %><%out.print("HelloWorld for testing the traversal of the map and list value stacks"); %> <S:iteratorvalue= "#request. Map1"var= "List">Map_key:<S:propertyvalue= "#list. Key"/></BR> <S:iteratorvalue= "#list. Value"var= "Current">List Value:<S:propertyvalue= "Current"/></BR> </S:iterator> </S:iterator> </Body>
Print results
HelloWorld for testing the traversal of the map and list value stacks
Map_key:b
List value: list2-1
List value: list2-2
List value: list2-3
Map_key:a
List value: List1-1
List value: List1-2
List value: List1-3
The second structure of list<map<k,v>>
<% ListList= newarraylist<map<string,string>> (); Map map1 = new HashMap<String, String>(); Map1.put ("A", "map1-1"); Map1.put ("B", "map1-2"); Map map2 = new HashMap<String, String>(); Map2.put ("A", "map2-1"); Map2.put ("B", "map2-2"); Map2.put ("C", "map2-3"); List.add (MAP1); List.add (MAP2); Put it in the root stack rather than the map stack//Actioncontext.getcontext (). Getvaluestack (). push (list); Request.setattribute ("list", list); %><S:debug></S:debug> <%out.print("HelloWorld for testing the traversal of the map and list value stacks"); %> <S:iteratorvalue= "#request. List"var= "List1"></BR> <S:iteratorvalue= "#list1"var= "Map" ></BR> <S:propertyvalue= "#map. Key"/> <S:propertyvalue= "#map. Value"/> </S:iterator>
Print results
HelloWorld for testing the traversal of the map and list value stacks
b map1-2
A map1-1
b map2-2
C map2-3
A map2-1
About JSP using El and struts2 tags to traverse valuestack------> List<map<k,v>> and map<k,<list<xxx>> > 's Structure traversal