开发者

Need to loop through 2 arrays at the same time in JSTL

I have two arrays that I need to loop through. Using foreach, I can only loop through one at a time. A regular 开发者_StackOverflow中文版for(i = 0; i<7; i++) Loop would be great.


I think I see what you mean - you have two arrays (probably of equal size), and you want to loop so that you use the loop index to access each array.

If that's what you meant (and it's far from clear from your question), then you could do something like this (assuming arrayX and arrayY).

<c:forEach items="${arrayX}" varStatus="loop">
    <c:out value="${arrayX[loop.index]}"/>
    <c:out value="${arrayY[loop.index]}"/>
</c:forEach>

This uses arrayX to get the iterator, but then uses indexed lookups into arrayX and arrayY.

varStatus is described here .


Here is something from JSTL in Action:

 <c:forEach begin="1" end="5" var="current">
    <c:out value="${current}"/>
</c:forEach>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜