Loop through JSTL tags

I have a collection of background servlets, not a specific object, but also a double loop.

    <% List list = (List) request.getParameter("list");

So this is no longer possible in JSP pages

for(int i=0;i<list.size();i++)

Because .size() cannot be used.

with JSTL tags

The items attribute of the c:forEach tag supports all standard collection types provided by the Java platform.

varStatus is used to create a scoped variable (which only works within the current tag body). However, the variable named by the varStatus property does not store the current index value or the current element, but is assigned to an instance of the javax.servlet.jsp.jstl.core.LoopTagStatus class.

current: The item (of the collection) for the current iteration.
index: The iteration index of the current iteration starting from 0.
count: The iteration count starting from 1 for the current iteration.
first: It is used to indicate whether the current iteration is the first iteration. This property is of type boolean.
last: It is used to indicate whether the current iteration is the last iteration. This property is of type boolean.
begin: The value of the begin attribute.
step: the value of the step attribute

Import the tag library first

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

I want to traverse the value I want, so use <c:if>条件 <c:if/>to judge

<table>
        <tr>
            <td>学生学号</td>
            <td>学生姓名</td>
            <td>学生班级</td>           
            <td>分数</td>     
        </tr>
        <c:forEach items="${requestScope.OneScoreList}" var="row" varStatus = "f1"> //OneScoreList是后台setAttribute("OneScoreList",list)的值
            <tr>
                <c:forEach items="${row}" var="item" varStatus="f2" begin="0">             
                    <c:if test="${f2.index==0 }">
                        <td><c:out value="${item}" /></td>
                        <c:set var="stuid" value="${item}" />
                    </c:if>
                    <c:if test="${f2.index==1 }">
                        <td><c:out value="${item}" /></td>
                    </c:if>
                    <c:if test="${f2.index==2 }">
                        <td><c:out value="${item}" /></td>
                    </c:if>             
                    <c:if test="${f2.index==7 }">
                        <td><c:out value="${item}" /></td>
                    </c:if>
                </c:forEach>                
            </tr>
        </c:forEach>
    </table>

Guess you like

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