It is necessary to simultaneously scroll through 2 arrays in JSTL

I have two arrays that I need to execute. Using foreach , I can only scroll one at a time. A regular for(i = 0; i<7; i++) loop for(i = 0; i<7; i++) would be big.

+7
jsp jstl
source share
2 answers

I think I understand what you mean, you have two arrays (possibly of equal size), and you want the loop to use the loop index to access each array.

If this is what you had in mind (and this is far from clear from your question), then you can 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 an iterator, but then uses indexed queries in arrayX and arrayY .

varStatus described here .

+10
source share

Here is something from JSTL in action :

  <c:forEach begin="1" end="5" var="current"> <c:out value="${current}"/> </c:forEach> 
+2
source share

All Articles