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.

Unified Expression Language<br />

Using Application-Specific Objects<br />

When possible, application behavior should be encapsulated in objects so that page designers<br />

can focus on presentation issues. Objects can be created by developers who are proficient in the<br />

<strong>Java</strong> programming language and in accessing databases and other services. <strong>The</strong> main way to<br />

create and use application-specific objects within a JSP page is to use JSP standard tags<br />

(discussed in “<strong>Java</strong>Beans Components” on page 165) to create <strong>Java</strong>Beans components and set<br />

their properties, and EL expressions to access their properties. You can also access <strong>Java</strong>Beans<br />

components and other objects in scripting elements, which are described in Chapter 9,<br />

“Scripting in JSP Pages.”<br />

Using Shared Objects<br />

<strong>The</strong> conditions affecting concurrent access to shared objects (described in “Controlling<br />

Concurrent Access to Shared Resources” on page 106) apply to objects accessed from JSP pages<br />

that run as multithreaded servlets. You can use the following page directive to indicate how a<br />

web container should dispatch multiple client requests:<br />

<br />

When the isThreadSafe attribute is set to true, the web container can choose to dispatch<br />

multiple concurrent client requests to the JSP page. This is the default setting. If using true, you<br />

must ensure that you properly synchronize access to any shared objects defined at the page<br />

level. This includes objects created within declarations, <strong>Java</strong>Beans components with page scope,<br />

and attributes of the page context object (see “Implicit Objects” on page 161).<br />

If isThreadSafe is set to false, requests are dispatched one at a time in the order they were<br />

received, and access to page-level objects does not have to be controlled. However, you still<br />

must ensure that access is properly synchronized to attributes of the application or session<br />

scope objects and to <strong>Java</strong>Beans components with application or session scope. Furthermore, it<br />

is not recommended to set isThreadSafe to false. <strong>The</strong> JSP page’s generated servlet will<br />

implement the javax.servlet.SingleThreadModel interface, and because the Servlet 2.4<br />

specification deprecates SingleThreadModel, the generated servlet will contain deprecated<br />

code.<br />

Unified Expression Language<br />

146<br />

<strong>The</strong> primary new feature of JSP 2.1 is the unified expression language (unified EL), which<br />

represents a union of the expression language offered by JSP 2.0 and the expression language<br />

created for <strong>Java</strong>Server Faces technology (see Chapter 10, “<strong>Java</strong>Server Faces Technology”)<br />

version 1.0.<br />

<strong>The</strong> expression language introduced in JSP 2.0 allows page authors to use simple expressions to<br />

dynamically read data from <strong>Java</strong>Beans components. For example, the test attribute of the<br />

following conditional tag is supplied with an EL expression that compares the number of items<br />

in the session-scoped bean named cart with 0.<br />

<strong>The</strong> <strong>Java</strong> <strong>EE</strong> 5<strong>Tutorial</strong> • June 2010

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

Saved successfully!

Ooh no, something went wrong!