Standard Action Elements

Actions are executed when a client requests a JSP page. They are inserted in a page using XML element syntax and perform such functions as input validation, database access, or passing control to another page. The JSP specification defines a few standard action elements, described in this section, and 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, you can use a shorthand notation in which 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.

Action elements, or tags, are grouped into tag libraries. The action name is composed of two parts, a library prefix and the name of the action within the library, separated by a colon (e.g., jsp:useBean). All actions in the JSP standard library use the prefix jsp, while custom actions can use any prefix except jsp, jspx, java, javax, servlet, sun, or sunw, as specified per page by the taglib directive.

Some action attributes accept a request-time attribute value, using the JSP expression syntax:

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

Here the ...

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.