A.2.2
Query
The connection can now be used to make a query.  The query element takes the body of the 
tag and make a query on it. The result gets inserted in place
SELECT account, balance FROM acct_table
where customer_number = <%= request.getCustno()%>
The implementation highlights are:
Tag Library Descriptor
Query has two mandatory attributes (in our example), and they are described as 
so in the TLD.  The TLD also associates QueryTag as the Tag handler class, 
and QueryExtraInfo as the TagExtraInfo for the query tag.
QueryTag
QueryTag needs access to its body; this it can do by defining a doAfterBody() 
method.  This method will take the BodyContent and convert it into a String.  
Then it will use the PageContext object to locate an SQL connection that was 
registered using the id that is the value to the connection attribute.  The result 
of the query will be registered in the PageContext with the value of the id 
attribute as its name.
QueryExtraInfo
This class is identical to BarExtraInfo from a previous example.
A.2.3
Iteration
Finally the query result can  later be used to present the data by dynamically creating a series 
of 
  • elements.
  • The balance for
  • account <%= row.getAccount()%> is <%= row.getBalance()%>
    Unlike query and connection, the foreach element does not define a new object for later use 
    but it defines (and redefines) a "row" object that is accessible within its start and end tags.
    The implementation of this tag requires the repeated evaluation of the body of the tag.
    Tag Library Descriptor
    Foreach has two mandatory attributes (in our example), and they are described 
    as so in the TLD.  The TLD also associates ForEachTag as the Tag handler 
    class, and ForEachExtraInfo as the TagExtraInfo for the foreach tag.
    135
    JavaServer Pages 1.1 Specification  
    November 30, 1999
    
    
    
    
    JSP Web Hosting JavaServer Pages Specifications JSP Hosting
    
    
    
    
    
     
    TotalRoute.net Business web hosting division of Vision Web Hosting Inc. All rights reserved.