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

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

分类: JSP 13018人阅读 评论(2) 收藏 举报

  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/wang3680/p/302d8e4c54511f31b116cae584906428.html