& Lt; c: forEach/& gt; label in jstl, jstlforeach

Source: Internet
Author: User

<C: forEach/> label in jstl, jstlforeach

<C: forEach> labels have the following attributes:

 

Attribute Description Required Default Value
Items Information to be recycled No None
Begin Start Element (0 = first element, 1 = second element) No 0
End Last element (0 = first element, 1 = second element) No Last element
Step Step size of each iteration No 1
Var Variable name of the current entry No None
VarStatus Variable name that represents the loop status No None

 

 

 

 

 

 

 

<C: forEach> instance demonstration
<% @ Taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %> 

 

 

The running result is as follows:


Item 1Item 2Item 3Item 4Item 5

 

 
C: forEach varStatus attribute

Current (in the set) of the current iteration
Index the index of the current iteration starting from 0
Count the number of current iterations starting from 1
First indicates whether the current iteration is the first iteration.
Last indicates whether the current iteration is the mark of the last iteration.
Begin Attribute Value
End Attribute Value
Step Attribute Value

 

 

For example:

<c:forEach var="item" items="${contents}" varStatus="status">
            <tr   <c:if test="${status.count%2==0}">bgcolor="#CCCCFE"</c:if> align="left">
              xxx          
        </tr>
</c:forEach>


 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.