[JSP] How c:forEach outputs the serial number

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 .


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325525019&siteId=291194637