c:foreach如何输出序号

Posted Henu丶雨巷

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c:foreach如何输出序号相关的知识,希望对你有一定的参考价值。

关键在于<c:forEach>的varStatus属性,具体代码如下:   
  
<table width="500" border="0" cellspacing="0" cellpadding="0">  
<tr>  
    <th>序号</th>  
    <th>姓名</th>  
</tr>  
<c:forEach var="student" items="${ students}" varStatus="status">  
<tr>  
    <td>${ status.index + 1}</td>  
    <td>${ student.name}</td>  
</tr>  
</c:forEach>  
</table>  
  
备注:status.index是从0开始的。  

以上是关于c:foreach如何输出序号的主要内容,如果未能解决你的问题,请参考以下文章