Name
<c:forEach>
Synopsis
The <c:forEach>
action evaluates its body a fixed number
of times or once for each element in a
collection. The current element (or the current index if no
collection is specified), and the iteration status can be exposed to
action elements in the body through nested variables.
The action accepts collections of the types listed in the Attributes
table. The type of the current element is the type of the underlying
collection, with two exceptions. For an array of a primitive type,
the current element is exposed as an instance of the corresponding
wrapper class (Integer
, Float
,
etc.) For a java.util.Map
, the current element is
exposed as a java.util.Map.Entry
.
Syntax 1: Iteration over collection elements
<c:forEach items="collection
" [var="var
"] [varStatus="varStatus
"] [begin="startIndex
"] [end="stopIndex
"] [step="increment
"]>JSP elements
</c:forEach>
Syntax 2: Fixed number of iterations
<c:forEach [var="var
"] [varStatus="varStatus
"] begin="startIndex
" end="stopIndex
" [step="increment
"]>JSP elements
</c:forEach>
Attributes
Attributename |
Java type |
Dynamic valueaccepted |
Description |
---|---|---|---|
items |
|
Yes |
The collection to iterate over. |
var |
|
No |
The name of the nested variable holding the current element. |
varStatus |
|
No |
The name of the nested variable holding the
|
begin |
|
Get JavaServer Pages, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.