1.首先在JSP页面中引入
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
2.关键在于<c:forEach>的varStatus属性,具体代码如下:
<table >
<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开始的。
本文介绍如何在JSP页面中利用<c:forEach>标签展示带有序号的学生名单,通过设置varStatus属性来获取当前项的索引,并进行序号的自增处理。
1741

被折叠的 条评论
为什么被折叠?



