Two dimensional arraylist with c:foreach jstl tag

随声附和 提交于 2019-12-11 03:45:23

问题


I'm using a two dimension arraylist in two imbricated JSTL <c:forEach>:

<select multiple size="30">
    <c:forEach var="uri" items="${defaultResult}" varStatus="iterator">
        <c:forEach var="cate" items="${defaultResult[iterator.index]}">
         <option value="${defaultResult[iterator.index][0]}"> ${cate}[1]</option>
        </c:forEach> 
    </c:forEach>
</select>

but the indexes seem not to be working, for example the values returned by ${cate}[1] are all the values of any dimension followed by [1]

If you have any idea to solve my problem it would be helpful.


回答1:


It needs to go inside the expression, not outside.

${cate[1]}

By the way, why don't you just access the var of the first loop?

<c:forEach var="uri" items="${defaultResult}">
    <c:forEach var="cate" items="${uri}">
        <option value="${uri[0]}">${cate[1]}</option>
    </c:forEach> 
</c:forEach>



回答2:


It worked for me:

.java:

private int[][] childAges; // [room][child] = age
.....

.jsp:

<c:forEach var="childAge" items="${childAges}" >
    <c:forEach var="age" items="${childAge}" >
        ${age}
    </c:forEach>
</c:forEach>


来源:https://stackoverflow.com/questions/6187885/two-dimensional-arraylist-with-cforeach-jstl-tag

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!