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

Developing a Simple Action

As you have seen in the previous chapters, a custom action element in a JSP page consists of a start tag (possibly with attributes), a body, and an end tag:

<prefix:actionName attr1="value1" attr2="value2">
  The body
</prefix:actionName>

If the action element doesn’t have a body, the following shorthand notation can be used instead:

<prefix:actionName attr1="value1" attr2="value2" />

A Java class referred to as a tag handler implements the action’s behavior. In order for the tag handler to do anything interesting, it needs access to the request and scope information, as well as the action element’s attribute values (if any). The container calls methods defined in the Tag interfaces to provide it with this information. For the attribute values, the JSP container treats the tag handler as a bean and calls a property setter method corresponding to each attribute. The Tag interface also contains methods called by the container when the start tag and end tag are encountered, as shown in Figure 20-2.

Tag interface methods and property setter methods

Figure 20-2. Tag interface methods and property setter methods

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 ...

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