Java Reference
In-Depth Information
Table 3-17. <c:forEach> Attributes
Name
Type
Description
var
String
Name of the exported scoped variable for the current item of the iteration.
items
Arrays, Collection,
Enumeration, Iterator,
Map, String
Collection of items to iterate over.
varStatus
String
Name of the exported scoped variable for the status of the iteration. The
object exported is of type
javax.servlet.jsp.jstl.core.LoopTagStatus .
begin
int
If items are specified, iteration begins at the item located at the specified
index. The first item of the collection has index 0.If items are not specified,
then iteration begins with index set at the value specified.
end
int
If items are specified, then iteration ends at the item located at the
specified index (inclusive).If items are not specified, then iteration ends
when the index reaches the value specified.
step
int
Iteration will process only every step item , starting with the first one.
To iterate over a collection of objects, use the following syntax:
<c:forEach[var="varName"] items="collection" [varStatus="varStatusName"]
...body content ....
</c:forEach>
To iterate a fixed number of times, use the following syntax:
<c:forEach [var="varName"] [varStatus="varStatusName"]
begin="begin" end="end" [step="step"]>
...body content ...
</c:forEach>
Listing 3-47 illustrates a simple usage of <c:forEach> .
Listing 3-47. Using <c:forEach>
<body>
<c:forEach var="i" begin="1" end="3">
Item <c:out value="${i}"/><p>
</c:forEach>
</body>
Here's the output:
Item 1
Item 2
Item 3
 
 
Search WWH ::




Custom Search