EL expressions are invoked with this syntax: ${expr} , where expr represents an expression. Expressions can consist of:
Until JSP 2.0, when the JSTL expression language is scheduled to be incorporated into the JSP specification, you can only use EL expressions to specify attributes of JSTL actions; for example, the following code fragment from the Database Actions chapter specifies an SQL data source as a comma-separated string constructed with four EL expressions and three commas: [5]
<sql:setDataSource dataSource='${url},${driver},${user},${pwd}' scope='session'/> If you upgrade to JSP 2.0, you can have EL expressions in template text; for example, you will be able to execute an SQL query like this: [6]
<%-- This only works with containers that support JSP 2.0 --%> <sql:query> ${customerQuery} </sql:query> The customerQuery scoped variable referenced by the EL expression in the preceding code fragment is a string that specifies a particular query. Until JSP 2.0, you are restricted to using EL expressions to specify attributes for JSTL actions; for example, you can still execute the query listed in the preceding code fragment like this: <%-- This works with containers that support JSP 1.2 --%> <sql:query sql='${customerQuery}'/> Alternatively, you could use the <c:out> action if you had to specify the query in the body of the action like this: <%-- This also works with containers that support JSP 1.2 --%> <sql:query> <c:out value='${customerQuery}'/> </sql:query> The <c:out> action in the preceding code fragment sends the string stored in the customerQuery scoped variable to the current JspWriter , which points to the <sql:query> action's body, so the preceding code fragment is functionally equivalent to the two preceding code fragments . |