JSTL tag loop traversal

I have a collection of back-end servlet s, which is not a specific object, but also a double loop.

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

So we can't do this again in JSP pages

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

Because. size() is not available.

Tag with JSTL

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

varStatus is used to create a scoped variable that works only within the current label body. However, the variable named by the varStatus attribute does not store the current index value or current element, but rather gives an instance of the javax.servlet.jsp.jstl.core.LoopTagStatus class.

Current: the item in the current iteration (in the collection).
Index: the index of the current iteration starting from 0.
Count: the current count of iterations starting from 1.
First: used to indicate whether the current iteration is the first iteration. This attribute is of boolean type.
Last: used to indicate whether the current iteration is the last iteration. This attribute is of boolean type.
Begin: the value of the begin property.
Step: the value of the step attribute

Import label library first

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

I want to traverse the value I want, so I use the < C: if > condition < C: if / > to judge

<table>
        <tr>
            <td>Student ID</td>
            <td>Student name</td>
            <td>Student class</td>           
            <td>Fraction</td>     
        </tr>
        <c:forEach items="${requestScope.OneScoreList}" var="row" varStatus = "f1"> //OneScoreList is the value of the background 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>

Keywords: Attribute JSP Java

Added by wannalearnit on Sun, 05 Apr 2020 11:21:47 +0300