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開始的。status.count是從1開始的。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM