Action Elements

Action elements use XML element syntax and represent components that are invoked when a client requests the JSP page. They may encapsulate functionality such as input validation using beans, database access, or passing control to another page. The JSP specification defines a few standard action elements, described in this section, and also includes a framework for developing custom action elements.

An action element consists of a start tag (optionally with attributes), a body, and an end tag. Other elements can be nested in the body. Here’s an example:

<jsp:forward page="nextPage.jsp">
  <jsp:param name="aParam" value="aValue" />
</jsp:forward>

If the action element doesn’t have a body, a shorthand notation can be used where the start tag ends with "/>" instead of ">“, as shown by the <jsp:param> param action in this example. The action element name and attribute names are case-sensitive.

Some standard action attributes accept a request-time attribute value (marked with “RT expression” in the “Dynamic value accepted” column in the Attributes table for each action that follows), using the JSP expression syntax:

<% String headerPage = currentTemplateDir + "/header.jsp"; %>
<jsp:include page="<%= headerPage %>" />

The attribute descriptions for each action in this section define whether a request-time attribute value is accepted or not.

JSTL actions, described in Appendix B, and custom actions may accept JSTL Expression Language (EL) expressions for dynamic values instead ...

Get JavaServer Pages, Second 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.