Developing a Basic Action
The main difference between the simple and classic tag handler APIs
is that while the SimpleTag
interface has only one
method for asking the tag handler to complete its processing, the
Tag
interface has two: doStartTag(
)
and doEndTag( )
(the
Tag
subinterfaces for more specialized classic tag
handlers add even more methods). The container calls these methods
when the start tag and end tag are encountered, as shown in Figure 21-4.
Attribute values are set using bean setter methods, just as for the
simple tag handler. The doStartTag( )
and
doEndTag( )
method return values that controls
what happens next, for instance how to deal with the custom action
body. This is another significant difference compared to the simple
tag handler; a classic tag handler needs to ask the container
(through the return value) to evaluate the body rather than doing it
itself.
A tag handler that implements just the Tag
interface can add dynamic content to the response body and set
response headers, add or remove variables in one of the JSP scopes,
and tell the container to either include the action
element’s body in the response or ignore it.
Here are the most important methods of the
Tag
interface:
public void setPageContext(PageContext pageContext); public int doStartTag( ) throws JspException; public int doEndTag( ) ...
Get JavaServer Pages, 3rd Edition 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.