Iterate over Map object using JSTL
Is it possible to implement the following using plain JSTL:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<table>
<%
java.util.Map msgMap = (java.util.Map) request.开发者_如何学CgetAttribute("messageMap");
for(int loopCount=1;loopCount>0;loopCount++) {
if(msgMap.containsKey("/packagesBO/packages["+loopCount+"]/packageId")) {
%>
<tr>
<td><%=msgMap.get("/packagesBO/packages["+loopCount+"]/packageName")%></td>
</tr>
<%
}
else {
break;
}
}
%>
</table>
Yes it is have a look at c:forEach and c:if and expression language. Here an example (not tested):
<table>
<c:forEach var="entry" items="${messageMap}" varStatus="num">
<c:if test=${messageMap['/packagesBO/packages["+num.count+"]/packageId']}>
<tr>
<td><c:out value="${messageMap['/packagesBO/packages[\"+num.count+\"]/packageId']"}/></td>
</tr>
</c:if>
</c:forEach>
</table>
精彩评论