WebLogic JSP Reference 13-11
The following two conditions must be satisfied when using JSPX:
■
web.xml – The web-app must define the Servlet version attribute as 2.4 or higher; otherwise, all EL functions are ignored.
■
TLD file – Namespace declaration is required for the jsp prefix, as follows: html xmlns:jsp=http:java.sun.comJSPPage;
The following shows a conditional action that uses the JSP EL to test whether a property of a bean is less than 3.
c:if test={bean1.a 3} ...
c:if
Note that the normal JSP coercion mechanism already allows for: mytags:if test=true . There may be literal values that include the character sequence {. If
this is the case, a literal with that value can be used as shown here:
mytags:example code=an expression is {{}expr} The resulting attribute value would then be the string an expression is {expr}.
13.10.2 Expressions and Template Text
You can use the JSP EL directly in template text; this can be inside the body of custom or standard actions or in template text outside of any action. An exception to this use is
if the body of the tag is tag dependent or if the JSP EL is turned off usually for compatibility issues explicitly through a directive or implicitly.
The semantics of a JSP EL expression are the same as with Java expressions: the value is computed and inserted into the current output. In cases where escaping is desired
for example, to help prevent cross-site scripting attacks, you can use the JSTL core tag c:out. For example:
c:out value={anELexpression} The following shows a custom action where two JSP EL expressions are used to access
bean properties: c:wombat
One value is {bean1.a} and another is {bean2.a.c}. c:wombat
13.11 JSP Expression Language Implicit Objects
There are several implicit objects that are available to JSP EL expressions used in JSP pages. These objects are always available under these names:
■
pageContext—Represents the pageContext object.
■
pageScope—Represents a Map that maps page-scoped attribute names to their values.
Note: These rules are equivalent to the JSP 2.1 conversions, except
that empty strings are treated differently.
13-12 Developing Web Applications, Servlets, and JSPs for Oracle WebLogic Server
■
requestScope—Represents a Map that maps request-scoped attribute names to their values.
■
sessionScope—Represents a Map that maps session-scoped attribute names to their values.
■
applicationScope—Represents a Map that maps application-scoped attribute names to their values.
■
param—Represents a Map that maps parameter names to a single String parameter value obtained by calling
ServletRequest.getParameterString name.
■
paramValues—Represents a Map that maps parameter names to a single String[] of all values for that parameter obtained by calling
ServletRequest.getParameterValuesString name.
■
header—Represents a Map that maps header names to a single String header value obtained by calling ServletRequest.getHeaderstring name.
■
headerValues—Represents a Map that maps header names to a String[] of all values for that header obtained by calling
ServletRequest.getHeadersString name.
■
cookie—Represents a Map that maps cookie names to a single Cookie object. Cookies are retrieved according to the semantics of
HttpServletRequest.getCookies. If the same name is shared by multiple cookies, an implementation must use the first one encountered in the array of
Cookie objects returned by the getCookies method. However, users of the cookie implicit objects must be aware that the ordering of cookies is currently
unspecified in the servlet specification.
■
initParam—Represents a Map that maps context initialization parameter names to their String parameter value obtained by calling
ServletRequest.getInitParameterString name.
Table 13–4 shows some examples of using these implicit objects:
13.12 JSP Expression Language Literals and Operators