JSP for foreach tag for two variables
I want to do something like this
<c:forEach var="item1" items="List1" var="item2" items="List2"> <p> ${item1} ${item2}</p> </c:forEach> One solution is to iterate through the list if both are the same size
<c:forEach var="i" begin="0" end="$(fn:length(List1))"> <p> <%= List1.get(i) %> <%= List2.get(i)%> //wrong syntax </c:forEach> Any idea how to achieve this.
You can call varStatus.index to get the index of the current round, and then use it to find the second list. Remember the length of the List , though, or it will throw an exception. Set items with a List having a maximum of two.
<c:forEach var="element" items="${List1}" varStatus="status"> <p> ${element} ${List2[status.index]} </c:forEach>