CHAPTER 3: Best Practices in Java EE Web Development 139
Table 3-17.
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 ....
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 ...
Listing 3-47 illustrates a simple usage of
Listing 3-47. Using
Item
Here’s the output:
Item 1
Item 2
Item 3