2.2 Expressions

   

EL expressions are invoked with this syntax: ${expr} , where expr represents an expression. Expressions can consist of:

  • Identifiers ” see "Identifiers" on page 43

  • Binary and unary operators ” see "Operators" on page 44

  • String, boolean, integer, and floating-point literals and null ” see "Literal Values" on page 63

  • Implicit objects, such as param , cookie , or header ” see "Implicit Objects" on page 64

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]

[5] See "Specify Your Data Source with <sql:setDataSource>" on page 369.

 <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]

[6] The JSP 2.0 specification is scheduled to be completed in late 2002.

 <%-- 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 .

   


Core JSTL[c] Mastering the JSP Standard Tag Library
Core JSTL[c] Mastering the JSP Standard Tag Library
ISBN: 131001531
EAN: N/A
Year: 2005
Pages: 124

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net