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. Template text and other JSP 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> 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 “Yes” in the “Dynamic value accepted” column in the Attributes table for each action that follows). For such an attribute, the value can be specified as an EL or Java expression, or by a <jsp:attribute> element:

<% String headerPage = currentTemplateDir + "/header.jsp"; %> <%-- Using a Java expression --%> <jsp:include page="<%= headerPage %>" /> <% pageContext.setAttribute("scopedVar", headerPage); <%-- Using an EL expression --%> <jsp:include page="${scopedVar}" /> <%-- Using a <jsp:attribute> ...

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.