The JSTL expression language is a simple language inspired by ECMAScript (also known as JavaScript) and XPath. The expression language provides:
All of the features listed above are described in this chapter. Throughout this book, for convenience the expression language is referred to with the acronym EL and JSTL expressions are referred to as EL expressions. How the Expression Language WorksNearly all of the JSTL actions have one or more dynamic attributes that you can specify with an EL expression; [2] for example, you can specify a request parameter with the <c:out> action's value attribute like this:
<c:out value='${param.emailAddress}'/> The preceding expression displays the value of a request parameter named emailAddress . You can also use EL expressions to perform conditional tests, for example: <c:if test='${not empty param.emailAddress}'>...</c:if> The body of the preceding <c:if> action is evaluated if the emailAddress request parameter is not empty, meaning neither null nor an empty string. If you're using JSTL with JSP 1.2, you can only use JSTL expressions to specify values for JSTL action attributes, as illustrated above. [3] All JSTL actions that have dynamic attributes interpret EL expressions before they are passed to the action's tag handler, so the expression language is applied ”and values are typically coerced ”before the tag handler gets them.
How to Use the Expression LanguageAttributes of JSTL actions can be specified with EL expressions in one of three ways. First, an attribute can be specified with a single expression like this: [4]
<jstl:action value='${expr}'/> In the preceding code fragment, the expression ${expr} is evaluated and its value is coerced to the type expected by the value attribute. Attribute values can also be specified as strings, like this: <jstl:action value='text'/> The string specified for the value attribute in the preceding code fragment is coerced to the type expected by that attribute. Finally, attribute values can consist of one or more expressions intermixed with strings, like this: <jstl:action value='${expr}text${expr}${expr}more text${expr}'/> In the previous code fragment, each of the four expressions is evaluated in order from left to right, coerced to a string, and concatenated with the intermixed text. The resulting string is subsequently coerced to the value expected by the value attribute. |