开发者

Iterate over Map object using JSTL

开发者 https://www.devze.com 2023-01-20 22:21 出处:网络
Is it possible to implement the following using plain JSTL: <%@ page language=\"java\" contentType=\"text/html; charset=ISO-8859-1\"

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号