Mixing Action Elements and Scripting Elements
Even when you use custom actions and the JSTL, you may occasionally want to use small amounts of scripting code. One case is for setting attribute values to dynamic values for an action that doesn’t support EL expressions. Another is for a quick fix or prototyping, when creating a custom action seems like overkill.
Using an Expression Element to Set an Attribute
In all examples so far, dynamic action attribute values are set using
EL expressions, but that isn’t always possible. None
of the JSP standard actions (those with prefix
jsp
) support EL expressions in JSP 1.2. Custom
actions may support EL expressions, but to do so, they must
incorporate code that evaluates the expression, as described in Chapter 22. It’s expected that the EL
will be included in the next JSP specification version, allowing EL
expressions to be used for attribute values in all standard actions
as well as in all custom actions (without requiring special
evaluation code in the tag handlers), so this is likely a temporary
problem.
Until the JSP specification includes the EL , you must use a JSP
expression to set a dynamic attribute value for actions that
don’t support EL expressions. A JSP expression used
this way is called a request-time attribute
value
. Here is an
example of how it can be used to set the value
attribute of the standard <jsp:param>
action:
<jsp:forward page="prodInfo.jsp"> <jsp:param name="id" value='<%= request.getParameter("prodId") %>' /> </jsp:forward> ...
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.