JSP Tag Libraries

Скачать в pdf «JSP Tag Libraries»


Called by the JSP runtime to prompt the tag handler to perform any cleanup necessary before it is reused.

Some tags need to be able to inspect their bodies and make changes to them before they’re included in the JSP’s response to the user. These tags implement an interface called BodyTag (which itself extends from Tag), and offer extra methods to facilitate body manipulation. In addition to the methods in table 4.3, BodyTag includes those in table 4.4.

Table 4.4 BodyTag‘s additional methods

Method name


setBodyContent(BodyContent bc)

Called by the JSP runtime to set a BodyContent object for this tag. This gives the tag handler access to its processed body.


Called by the JSP runtime to prompt the tag handler to perform any needed initialization before processing its body.


Called by the JSP runtime after it reads in and processes a tag’s body to prompt the tag handler to perform any inspection or modification of the processed body.

Both the Tag and the BodyTag interface have convenience classes that are also part of the custom tag API. These convenience classes, TagSupport and BodyTagSup-port, offer default implementations of Tag and BodyTag interfaces (respectively) and facilitate the writing of a tag handler. Most tag handlers we’ll develop extend from one of these convenience classes, rather than implementing all their interface methods explicitly. We’ve seen examples of these tag handlers in chapter 3, and will see many more in the coming chapters.

Seven more classes round out the custom tag API (table 4.2). At least one of them, BodyContent, will be recognizable from chapter 3. BodyContent is a class that represents the processed body of a tag and offers methods for reading this body and writing back to it. The complete method list for BodyContent can be found in table 4.5.

Скачать в pdf «JSP Tag Libraries»