JSTL在表中获取序列号

时间:2014-07-16 05:57:18

标签: java spring-mvc jstl

我在每个循环中使用JSTL来迭代列表&在表格中显示该数据。

我想知道如何在该表中显示序列号。

<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。

3 个答案:

答案 0 :(得分:3)

您应该使用该标记的 varStatus 属性来跟踪循环状态

<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>

这应该适合你。

答案 1 :(得分:0)

尝试使用varStatus property

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

答案 2 :(得分:0)

                  This should be work definitly
       <c:forEach items="${item.getApps()}" var="app" varStatus="counter">
       <tr><td> ${counter.index+1}"</td>             
       <td><c:out value="${app.getApp()}"></c:out></td>
       </tr>
       </c:forEach>