Now whenever you add the text <djs:hello /> to your JSP, it will be replaced by the text
Tags with Bodies
Now that you have seen a custom tag without a body, let's create a tag that uses a body. All tag
handlers with bodies must implement the BodyTag interface. The BodyTag interface extends the
Tag interface by adding functionality to handle body content. It does this by adding three new
methods. Each one of these methods is described in Table 19.3.
T ABLE 19.3
Methods Added by the BodyTag Interface
Used by the container to set the current content of the tag's body.
Executed once per invocation after the setBodyContent() method
and before the evaluation of the tag's body.
Called by the container after the body content has been evaluated.
Like tags without bodies, tags with bodies also have a helper class. Their helper is
BodyTagSupport and it extends TagSupport and implements the BodyTag interface.
When the JSP container encounters a tag with a body it performs the following steps:
The setPageContext() method is called, setting the current page's PageContext .
The setParent() method is called with a reference to the parent Tag object, if this is a
nested tag, or null if not.
The doStartTag() is then called. It will return either EVAL_BODY_INCLUDE or SKIP_BODY .
If EVAL_BODY_INCLUDE is returned, the container should evaluate the body of the tag. If
SKIP_BODY is returned, the container will not evaluate the body.
The setBodyContext() is then called.
The doInitBody() is then called.
The doAfterBody() is then called repeatedly as long as it returns EVAL_BODY_TAG .
The doEndTag() method is called when the closing tag element is encountered. It can
return either of two values: EVAL_PAGE , which tells the container to continue evaluating
the page, or SKIP_PAGE , which tells the container to stop evaluating the rest of the page.
The final step performed by the container is to call the release() method. This method
is used to reset class level attributes and to release any allocated resources.