问题
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