1. First introduce in the JSP page
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
2. The key lies in the varStatus attribute of <c:forEach>, the specific code is as follows:
<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> Note: status.index starts from 0 .