Java Reference
In-Depth Information
The values of the var and dataSource attributes of the tag correspond to the values
we entered in the Variable Name and Data Source fields in the Insert DB Query
window. Since page scope is the default scope, we don't see an attribute defining the
variable scope. Had we picked a scope different from page, NetBeans would have
added a scope attribute to the tag, containing the scope for the variable as its value
(that is scope="session" ).
We then need to add some logic to our page to traverse the result set. This is
typically done through the <c:forEach> tag. After adding the required markup, the
body of our page now looks like this:
<body>
<h2>Hello World!</h2>
<sql:query var="allRows" dataSource="jdbc/sample">
SELECT name, city, state FROM customer
</sql:query>
<table border="1">
<thead>
<tr>
<th>Name</th>
<th>Location</th>
</tr>
</thead>
<tbody>
<c:forEach var="currentRow"
items="${allRows.rows}">
<tr>
<td>${currentRow.name}</td>
<td>${currentRow.city},
${currentRow.state}
</td>
</tr>
</c:forEach>
</tbody>
</table>
</body>
Notice how we dynamically generate table rows with the <c:forEach> tag.
 
Search WWH ::




Custom Search