Search code examples
javaspring-mvcjstl

JSTL get serial number in a table


I am using JSTL for each loop for iteration over a list & display that data in a table.

I would like to know how to display the serial number in that table.

<c:forEach items="${item.getApps()}" var="app">
<tr><td>....</td>             //need to display serial number here
<td><c:out value="${app.getApp()}"></c:out></td>
</tr></c:forEach>

TIA.


Solution

  • You should use varStatus attribute of that tag which keep track of loop status

    <c:forEach items="${item.getApps()}" var="app" varStatus="counter">
    <tr><td> ${counter.count}"</td>             //need to display serial number here
    <td><c:out value="${app.getApp()}"></c:out></td>
    </tr></c:forEach>
    

    This should work for you.