JSTL

Page 55

the data returned from an SQL query. Class javax.servlet.jsp.jstl.sql.ResultSupport (see Chapter 16 “Java APIs") allows business logic developers to easily convert a ResultSet object into a javax.servlet.jsp.jstl.sql.Result object, making life much easier for a page author that needs to manipulate the data returned from a SQL query.

6.1.2

Map If the items attribute is of type java.util.Map, then the current item will be of type java.util.Map.Entry, which has the following two properties: ■ ■

key - the key under which this item is stored in the underlying Map value - the value that corresponds to this key

The following example uses <c:forEach> to iterate over the values of a Hashtable: <c:forEach var="entry" items="${myHashtable}"> Next element is ${entry.value}/> </c:forEach>

6.1.3

Iteration Status <c:forEach> also exposes information relative to the iteration taking place. The example below creates an HTML table with the first column containing the position of the item in the collection, and the second containing the name of the product. <table> <c:forEach var=”product” items=”${products}” varStatus=”status”> <tr> <td>${status.count}”</td> <td>${product.name}”</td> </tr> </c:forEach> </table>

See Chapter 16 “Java APIs" for details on the LoopTagStatus interface exposed by the varStatus attribute.

Chapter 6

Iterator Actions

39


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.