In EL, the square bracket operator is used to retrieve elements of an array and a collection.
For collections that implement the Java.util.Map interface, the square bracket operator uses the associated key to find the values stored in the map.
Specify the key in square brackets and return the corresponding value as the value of the expression.
For example, the expression ${map['key']} returns the value associated with the "key" key in the Map referenced by the map identifier.
When the value of the expression in the items property of forEach is java.util.Map, the type of the named variable in var is java.util.Map.Entry.
If var=entry , use the expression ${entry.key} to obtain 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 complies with the naming convention of JavaBeans.
<% Map<String,String> map2 = new HashMap(); map2.put("a","hello world"); map2.put("b","this is map"); request.setAttribute("map2",map2); %><c:forEach var="item" items="${map2}"> ${item.key} > ${item.value} <br> </c:forEach> <c:if test="${item.product!=null || fn:length(item.product) != 0}"> <c:forEach items="${item.product}" var="product"> <c:if test="${product.key=='userName'}"> ${product.value} </c:if> </c:forEach></c:if>The above is the method of traversing the map with jstl EL expressions introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!