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.

9 CHAPTER 9<br />

Scripting in JSP Pages<br />

JSP scripting elements allow you to use <strong>Java</strong> programming language statements in your JSP<br />

pages. Scripting elements are typically used to create and access objects, define methods, and<br />

manage the flow of control. Many tasks that require the use of scripts can be eliminated by using<br />

custom tag libraries, in particular the JSP Standard Tag Library. Because one of the goals of JSP<br />

technology is to separate static data from the code needed to dynamically generate content, very<br />

sparing use of JSP scripting is recommended. Nevertheless, there may be some circumstances<br />

that require its use.<br />

<strong>The</strong>re are three ways to create and use objects in scripting elements:<br />

■ Instance and class variables of the JSP page’s servlet class are created in declarations and<br />

accessed in scriptlets and expressions.<br />

■ Local variables of the JSP page’s servlet class are created and used in scriptlets and<br />

expressions.<br />

■ Attributes of scope objects (see “Using Scope Objects” on page 105) are created and used in<br />

scriptlets and expressions.<br />

This chapter briefly describes the syntax and usage of JSP scripting elements.<br />

<strong>The</strong> Example JSP Pages<br />

This chapter illustrates JSP scripting elements using webclient, a version of the hello1<br />

example introduced in Chapter 3, “Getting Started with Web Applications,” that accesses a web<br />

service.<br />

To deploy and run the webclient example using NetBeans IDE, follow these steps:<br />

1. Build and deploy the JAX-WS web service MyHelloService described in “Building,<br />

Packaging, and Deploying the Service” on page 480.<br />

2. In NetBeans IDE, select File→Open Project.<br />

271

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

Saved successfully!

Ooh no, something went wrong!