10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Implicit Objects<br />

<strong>The</strong> JSP expression language defines a set of implicit objects:<br />

■ pageContext: <strong>The</strong> context for the JSP page. Provides access to various objects including:<br />

■ servletContext: <strong>The</strong> context for the JSP page’s servlet and any web components<br />

contained in the same application. See “Accessing the Web Context” on page 124.<br />

■ session: <strong>The</strong> session object for the client. See “Maintaining Client State” on page 125.<br />

■ request: <strong>The</strong> request triggering the execution of the JSP page. See “Getting Information<br />

from Requests” on page 110.<br />

■ response: <strong>The</strong> response returned by the JSP page. See “Constructing Responses” on<br />

page 112.<br />

■ In addition, several implicit objects are available that allow easy access to the following<br />

objects:<br />

■ param: Maps a request parameter name to a single value<br />

■ paramValues: Maps a request parameter name to an array of values<br />

■ header: Maps a request header name to a single value<br />

■ headerValues: Maps a request header name to an array of values<br />

■ cookie: Maps a cookie name to a single cookie<br />

■ initParam: Maps a context initialization parameter name to a single value<br />

■ Finally, there are objects that allow access to the various scoped variables described in<br />

“Using Scope Objects” on page 105.<br />

■ pageScope: Maps page-scoped variable names to their values<br />

■ requestScope: Maps request-scoped variable names to their values<br />

■ sessionScope: Maps session-scoped variable names to their values<br />

■ applicationScope: Maps application-scoped variable names to their values<br />

JSP 2.1 provides two EL resolvers to handle expressions that reference these objects:<br />

ImplicitObjectELResolver and ScopedAttributeELResolver.<br />

A variable that matches one of the implicit objects is evaluated by ImplicitObjectResolver,<br />

which returns the implicit object. This resolver only handles expressions with a base of null.<br />

What this means for the following expression is that the ImplicitObjectResolver resolves the<br />

sessionScope implicit object only. Once the implicit object is found, the MapELResolver<br />

instance resolves the profile attribute because the profile object represents a map.<br />

${sessionScope.profile}<br />

Unified Expression Language<br />

ScopedAttributeELResolver evaluates a single object that is stored in scope. Like<br />

ImplicitObjectELResolver, it also only evaluates expressions with a base of null. This<br />

resolver essentially looks for an object in all of the scopes until it finds it, according to the<br />

behavior of PageContext.findAttribute(String). For example, when evaluating the<br />

Chapter 5 • <strong>Java</strong>Server PagesTechnology 161

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!