<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>