Foreground acquisition and traversal of map, list, and map (object, map)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.