is it possible to iterate two items simultaneously using foreach in jstl? is it possible to iterate two items simultaneously using foreach in jstl? spring spring

is it possible to iterate two items simultaneously using foreach in jstl?


You can call varStatus.index to get the index of the current round of iteration, and then use it as a lookup for the second list.

For example, if you have two lists people.firstnames and people.lastnames you can do:

<c:forEach var="p" items="${people.firstnames}" varStatus="status">  <tr>      <td>${p}</td>      <td>${people.lastnames[status.index]}</td>  </tr></c:forEach>