Custom Actions

Custom action elements can be developed by programmers to extend the JSP language; for instance, for application-specific presentation, localization, validation, or any other task not provided by the standard JSP action elements.

The general syntax for using a custom action element in a JSP page is the same as that for JSP standard actions: a start tag (optionally with attributes), a body, and an end tag. Other elements and template text can be nested in the body. Here’s an example:

<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 of the start tag and end tag:

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

Before you can use a custom action in a JSP page, you must declare the tag library containing the custom action by using the taglib directive, identifying the library and assigning the prefix to be used for all custom action elements in the page.

Get JavaServer Pages Pocket Reference 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.