Handling of Java.util.Map in Jstl el, and nested list

Source: Internet
Author: User

The associated key finds the value stored in the map. The key is specified in square brackets and the corresponding value is returned as the value of the expression. For example, an expression ${map[' Key '} returns the "key" in the map referenced by the map identifierthe value associated with the key. When the value of the expression in the Items property of foreach is Java.util.Map, then the type of the variable named in Var is java.util.Map.Entry. At this time var=entry, use the expression ${entry.key} to get the key name. Use the expression ${entry.value} to get the value of each entry. This is because the Java.util.Map.Entry object has Getkey and GetValue methods, and the expression language adheres to the naming convention of JavaBean. <%Map<String,String> MAP2 =NewHashMap (); Map2.put ("A", "Hello World"); Map2.put ("B", "This is map"); Request.setattribute ("Map2", MAP2); %> <br>Key-value pair traversal<br> <c:foreach var= "item" items= "${MAP2}" >${item.key}> ${item.value} <br> </c:forEach>Key Traversal<br> <c:foreach var= "item" items= "${MAP2}" >${item.key}<br> </c:forEach>Value Traversal<br> <c:foreach var= "item" items= "${MAP2}" >${item.value}<br> </c:forEach> <body> <br><br> <%List<String> list =NewArraylist<string>(); List.add ("First"); List.add ("Second"); List<String> List2 =NewArraylist<string>(); List2.add ("AAAAAA"); List2.add ("BBBBBB"); Map<String,List<String>> map =NewHashMap (); Map.put (A, list); Map.put ("B", List2); Request.setattribute ("Map", map); %>get the list value by key and traverse the list<br> <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 map value is a list that iterates through each item in the list directly<br> <c:foreach var= "item" items= "${map}" > <c:foreach items= "${item.value}" var= "it" >${it}<br> </c:forEach> </c:forEach>

Handling of Java.util.Map in Jstl el, and nested list

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.