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