Processing Tag Bodies

So far, you have seen tags that treat the text in the body of the tag as simple JSP (or HTML) data. But tags can also manipulate the tag body in any way they choose. A simple example would be a tag that interprets its body as an SQL statement and uses this to query the database. Listing 14.18 shows a simple use of such a tag.

Listing 14.18. Full Text of select.jsp
 1: <%@ taglib uri="/demo" prefix="demo" %>
 2: <HTML>
 3: <HEAD>
 4: <TITLE> Tag Library SQL Query Demo</TITLE>
 5: <BODY>
 6:   <demo:select>
 7:     SELECT * FROM Customer
 8:   </demo:select>
 9: </BODY>
10: </HTML>
					

The implementation of this select tag must state in the TLD that the body text is tag dependent, as shown in the following:

 <tag> <name>select</name> <tag-class>demo.SelectTag</tag-class> ...

Get Sams Teach Yourself J2EE™ in 21 Days now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.