[JSP] c:forEach 如何输出序号

 1 关键在于<c:forEach>的varStatus属性,具体代码如下:   
 2   
 3 <table width="500" border="0" cellspacing="0" cellpadding="0">  
 4 <tr>  
 5     <th>序号</th>  
 6     <th>姓名</th>  
 7 </tr>  
 8 <c:forEach var="student" items="${ students}" varStatus="status">  
 9 <tr>  
10     <td>${ status.index + 1}</td>  
11     <td>${ student.name}</td>  
12 </tr>  
13 </c:forEach>  
14 </table>  
15   
16 备注:status.index是从0开始的。
原文地址:https://www.cnblogs.com/fujilong/p/5347950.html