Java Reference
In-Depth Information
Iterating through Arrays or Collections with
the <c:forEach> Tag
Many times it is necessary to repeatedly generate markup which is almost identical.
A typical example is the need to generate table rows. The only difference between
the markup for each row is the contents of each cell, other than that the markup is
identical. In cases like this, it is useful to iterate through an array or collection of
objects, generating the required markup in each iteration.
For cases like this, JSTL provides the <c:forEach> tag, just like tags previously
discussed in this chapter. The <c:forEach> tag can be dragged from the NetBeans
palette and dropped into our page.
After dropping the JSTL For Each item into the appropriate location in our page, we
are prompted for additional information.
The value of the Collection text field must be a JSTL expression resolving to either
a class implementing the java.util.Collection interface, or to an array. In our
example, we are retrieving an ArrayList attached to the session scope with the
name customerList .
Search WWH ::

Custom Search