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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

You can specify an event listener using the deployment descriptor editor of NetBeans IDE by<br />

doing the following:<br />

1. Expand your application’s project node.<br />

2. Expand the project’s Web Pages and WEB-INF nodes.<br />

3. Double-click web.xml.<br />

4. Click General at the top of the web.xml editor.<br />

5. Expand the Web Application Listeners node.<br />

6. Click Add.<br />

7. In the Add Listener dialog, click Browse to locate the listener class.<br />

8. Click OK.<br />

Handling Servlet Errors<br />

Any number of exceptions can occur when a servlet executes. When an exception occurs, the<br />

web container generates a default page containing the message<br />

A Servlet Exception Has Occurred<br />

Sharing Information<br />

But you can also specify that the container should return a specific error page for a given<br />

exception. Review the deployment descriptor file included with the example to learn how to<br />

map the exceptions exception.BookNotFound, exception.BooksNotFound, and<br />

exception.OrderException returned by the Duke’s Bookstore application to errorpage.html.<br />

See “Mapping Errors to Error Screens” on page 93 for instructions on how to specify error pages<br />

using NetBeans IDE.<br />

Web components, like most objects, usually work with other objects to accomplish their tasks.<br />

<strong>The</strong>re are several ways they can do this. <strong>The</strong>y can use private helper objects (for example,<br />

<strong>Java</strong>Beans components), they can share objects that are attributes of a public scope, they can use<br />

a database, and they can invoke other web resources. <strong>The</strong> <strong>Java</strong> Servlet technology mechanisms<br />

that allow a web component to invoke other web resources are described in “Invoking Other<br />

Web Resources” on page 122.<br />

Using Scope Objects<br />

Sharing Information<br />

Collaborating web components share information by means of objects that are maintained as<br />

attributes of four scope objects. You access these attributes using the [get|set]Attribute<br />

methods of the class representing the scope. Table 4–3 lists the scope objects.<br />

Chapter 4 • <strong>Java</strong> ServletTechnology 105

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

Saved successfully!

Ooh no, something went wrong!