A.2
A Set of SQL Tags
The following is a possible set of SQL tags.  Note that this specific syntax is only used for 
pedagogical reasons, no endorsement is implied.
A.2.1
Connection, UserId, and Password
The connection tag creates a connection using some userid and password information. To 
show tag communication, userid and password are actually subelements of connection.
ref="connection.xml">
  <%=session.getUserid()%>
  <%=session.getPassword()%>
In this example the  con01  object is available after the element.
This example uses the run time stack so userid and password can locate their enclosing 
connection tag and can update userid and password data in there.  This example also uses 
PageContext to register the SQL connection object with the pagecontext using "con01" so it can 
be retrieed later.
Tag Library Descriptor
Indicates the names of the tags and their attributes.  It associates Tag handlers 
with the tags.  It also associates the ConnectionExtraInfo as the TagExtraInfo 
for connection.
UserIdTag
UserIdTag 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 findAncestorWithClass() static method on Tag to locate the 
enclosing connection tag instance and will set the desired userid information on 
that object.
PasswordTag
This Tag handler is equivalent to UserIdTag.
ConnectionTag
This Tag handler provides methods to setUserId() and to setPassword() that 
will be used by the enclosed actions; it also provides a getConnection() method 
that on demand computes the desired SQL connection.  This tag handler needs 
not be concerned with the body computation, but it will need to register the 
SQL connection object with the pageContext object if an ID is provided.
ConnectionExtraInfo
This class is identical to BarExtraInfo from a previous example.
Appendix 
134




JSP Web Hosting JavaServer Pages Specifications JSP Hosting




 
TotalRoute.net Business web hosting division of Vision Web Hosting Inc. All rights reserved.