Learn Java for Web Development

(Tina Meador) #1

138 CHAPTER 3: Best Practices in Java EE Web Development


Looping and Iteration


JSTL offers two useful actions for looping and iteration: for general data and


for string tokenizing.

Table 3-16 illustrates the actions for looping and iteration.


Table 3-16. Looping and Iteration Actions in the Core Tag Library


Action Description

<c:forEach> Iterates over a collection of objects
<c:forTokens> Iterates over tokens, separated by the supplied delimiters

The Action


The action iterates over a collection of objects.


Here’s the syntax for iterating over a collection of objects:


<c:forEach[var="varName"] items="collection"
[varStatus="varStatusName"]
[begin="begin"] [end="end"] [step="step"]>


... body content....



Here’s the syntax for iterating a fixed number of times:


<c:forEach [var="varName"]
[varStatus="varStatusName"]
begin="begin" end="end" [step="step"]>


.... body content...



Table 3-17 illustrates the attributes of the action.

Free download pdf