1. Map
Background code:
Map<String,String> map2 = new HashMap();map2.put("a","hello world");map2.put("b","this is map");request.setAttribute("map2",map2);
Front-end code:
<C: foreach Var = "item" items = "$ {MAP2}" >$ {item. key}> or $ {item ['a']} $ {item. value} <br> </C: foreach>
2. Map (object, map)
Background code:
List <string> List = new arraylist <string> (); list. add ("first"); list. add ("second"); List <string> list2 = new arraylist <string> (); list2.add ("aaaaaa"); list2.add ("bbbbbb"); Map <string, list <string> map = new hashmap (); // (list <map (K, v)> likewise) map. put ("A", list); map. put ("B", list2); Request. setattribute ("map", MAP );
Front-end code:
<C: foreach Var = "item" items = "$ {map ['a']}" >$ {item} <br> </C: foreach> <br> <C: foreach Var = "item" items = "$ {map ['B']}" >$ {item} <br> </C: foreach> <br> // The value of map is the list, and each item in the list is directly traversed. <br> <C: foreach Var = "item" items = "$ {map}"> <C: foreach items = "$ {item. value} "Var =" it ">$ {It} <br> </C: foreach>
Iii. List
Background code:
List list=new ArrayList();list.add(user1);list.add(user2);list.add(user3);request.setAttribute(“list”,list);
User is a class with the set/get Method
Front-end code:
<c:forEach var="user" items="${list}"> <c:out value="${user.username}" /> </c:forEach>
Foreground acquisition and traversal of map, list, and map (object, map)