O'Reilly logo

JavaServer Pages, Second Edition by Hans Bergsten

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Processing the Action Body

As you can see, it’s easy to develop the most basic type of tag handlers. For a tag handler that needs to read and process the element body, just a few more methods are needed. They are defined by the BodyTag interface, an interface that extends the IterationTag interface.

An action element’s body has many possible uses. It can be used for input values spanning multiple lines; the JSTL database actions described in Chapter 11 use the body this way. The SQL statement is often large, so it’s cleaner to let the page author write it in the action body instead of as an attribute value. A similar example is an action that processes the body content in one way or another before it’s added to the response. Chapter 14 shows how the JSTL <x:transform> action can process its XML body using the XSL stylesheet specified as an attribute. In both cases, the tag handler must be able to read the body content and therefore implement the BodyTag interface.

The body can also provide a service or a resource to tag handlers for nested action elements. One example is the JSTL <sql:transaction> action, also from Chapter 11. It provides the nested database actions with the Connection object that communicates with the database and ensures that the SQL statements in all actions are treated as one transaction that either fails or succeeds. We look at how this type of tag handler cooperation can be implemented in detail in Chapter 21. What’s important to note, however, is that the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required