You are on page 1of 2

Document Information

Preface

Part I Introduction Your choices regarding cookies on this site


1. Overview

The Java EE 5 Tutorial


2. Using the Tutorial Examples

Part II The Web Tier


3. Getting Started with Web Applications
By using our sites, Oracle and our third party partners may use cookies and similar technologies to collect user data for the following purposes:
4. Java Servlet Technology
Home | Download
required cookies are necessary for the site| to
PDF | FAQ for
function, | Feedback
example, to remember your log-in details and provide secure log-in
What Is a Servlet?
functional cookies help us to optimize the site, for example, to collect statistics, to save your preferences for social interactions or to enable you
The Example Servlets
to post comments on our site
Troubleshooting Duke's Bookstore Database Problems
advertising cookies allow Oracle and our third party partners to provide you with interest-based advertising and tailored content across your
Servlet Life Cycle browsers and devices The Example Servlets
Handling Servlet Life-Cycle Events This chapter uses the Duke’s Bookstore application to illustrate the tasks involved in programming servlets. The source code for the bookstore application is located in the
Defining the Listener Class Please visit our privacy policy fortut-install/javaeetutorial5/examples/web/bookstore1/
more information. directory, which is created when you unzip the tutorial bundle (see Building the Examples).
Specifying Event Listener Classes
Table 4-1 lists the servlets that handle each bookstore function. You can find these servlet classes in tut-
Handling Servlet Errors
Accept all install/javaeetutorial5/examples/web/bookstore1/src/java/com/sun/bookstore1/.
Decline all View and change cookie preferences Each programming task is illustrated by one or more servlets. For
Sharing Information example, BookDetailsServlet illustrates how to handle HTTP GET requests, BookDetailsServlet and CatalogServlet show how to construct responses, and
Using Scope Objects CatalogServlet illustrates how to track session information.
Controlling Concurrent Access to Shared Resources
Accessing Databases Table 4-1 Duke’s Bookstore Example Servlets

Initializing a Servlet
Function Servlet
Writing Service Methods Privacy Policy | Powered by
Getting Information from Requests Enter the bookstore BookStoreServlet
Constructing Responses
Create the bookstore banner BannerServlet
Filtering Requests and Responses
Programming Filters Browse the bookstore catalog CatalogServlet
Programming Customized Requests and Responses
Specifying Filter Mappings Put a book in a shopping cart CatalogServlet,
Invoking Other Web Resources BookDetailsServlet
Including Other Resources in the Response
Get detailed information on a specific book BookDetailsServlet
Transferring Control to Another Web Component

Accessing the Web Context Display the shopping cart ShowCartServlet


Maintaining Client State
Remove one or more books from the shopping cart ShowCartServlet
Accessing a Session
Associating Objects with a Session Buy the books in the shopping cart CashierServlet
Notifying Objects That Are Associated with a Session
Send an acknowledgment of the purchase ReceiptServlet
Session Management
Session Tracking
The data for the bookstore application is maintained in a database and accessed through the database access class database.BookDBAO. The database package
Finalizing a Servlet
also contains the class Book which represents a book. The shopping cart and shopping cart items are represented by the classes cart.ShoppingCart and
Tracking Service Requests
cart.ShoppingCartItem, respectively.
Notifying Methods to Shut Down
Creating Polite Long-Running Methods To deploy and run the application using NetBeans IDE, follow these steps:
Further Information about Java Servlet Technology
1. Perform all the operations described in Accessing Databases from Web Applications.
5. JavaServer Pages Technology
6. JavaServer Pages Documents 2. In NetBeans IDE, select File→Open Project.
7. JavaServer Pages Standard Tag Library
8. Custom Tags in JSP Pages
3. In the Open Project dialog, navigate to:
9. Scripting in JSP Pages tut-install/javaeetutorial5/examples/web/
10. JavaServer Faces Technology
11. Using JavaServer Faces Technology in JSP Pages 4. Select the bookstore1 folder.
12. Developing with JavaServer Faces Technology
13. Creating Custom UI Components 5. Select the Open as Main Project check box and the Open Required Projects check box.
14. Configuring JavaServer Faces Applications
15. Internationalizing and Localizing Web Applications
6. Click Open Project.

Part III Web Services 7. In the Projects tab, right-click the bookstore1 project, and select Undeploy and Deploy.
16. Building Web Services with JAX-WS
17. Binding between XML Schema and Java Classes 8. To run the application, open the bookstore URL http://localhost:8080/bookstore1/bookstore.
18. Streaming API for XML
To deploy and run the application using Ant, follow these steps:
19. SOAP with Attachments API for Java

Part IV Enterprise Beans 1. In a terminal window, go to tut-install/javaeetutorial5/examples/web/bookstore1/.


20. Enterprise Beans
21. Getting Started with Enterprise Beans
2. Type ant. This command will spawn any necessary compilations, copy files to the tut-install/javaeetutorial5/examples/web/bookstore1/build/ directory,
22. Session Bean Examples
and create a WAR file and copy it to the tut-install/javaeetutorial5/examples/web/bookstore1/dist/ directory.
23. A Message-Driven Bean Example
3. Start the Application Server.
Part V Persistence
24. Introduction to the Java Persistence API 4. Perform all the operations described in Creating a Data Source in the Application Server.
25. Persistence in the Web Tier
5. To deploy the example, type ant deploy. The deploy target outputs a URL for running the application. Ignore this URL, and instead use the one shown in the next
26. Persistence in the EJB Tier
step.
27. The Java Persistence Query Language

Part VI Services 6. To run the application, open the bookstore URL http://localhost:8080/bookstore1/bookstore.
28. Introduction to Security in the Java EE Platform
29. Securing Java EE Applications
To learn how to configure the example, refer to the deployment descriptor (the web.xml file), which includes the following configurations:
30. Securing Web Applications
A display-name element that specifies the name that tools use to identify the application.
31. The Java Message Service API
32. Java EE Examples Using the JMS API A set of filter elements that identify servlet filters contained in the application.
33. Transactions
34. Resource Connections A set of filter-mapping elements that identify which servlets will have their requests or responses filtered by the filters identified by the filter elements. A
35. Connector Architecture filter-mapping element can define more than one servlet mapping and more than one URL pattern for a particular filter.
Part VII Case Studies
A set of servlet elements that identify all the servlet instances of the application.
36. The Coffee Break Application
37. The Duke's Bank Application A set of servlet-mapping elements that map the servlets to URL patterns. More than one URL pattern can be defined for a particular servlet.
Part VIII Appendixes
A. Java Encoding Schemes
A set of error-page mappings that map exception types to an HTML page, so that the HTML page opens when an exception of that type is thrown by the application.
B. About the Authors
Troubleshooting Duke's Bookstore Database Problems
Index The Duke’s Bookstore database access object returns the following exceptions:

BookNotFoundException: Returned if a book can’t be located in the bookstore database. This will occur if you haven’t loaded the bookstore database with data or
the server has not been started or has crashed. You can populate the database by running ant create-tables.

BooksNotFoundException: Returned if the bookstore data can’t be retrieved. This will occur if you haven’t loaded the bookstore database with data or if the
database server hasn’t been started or it has crashed.

UnavailableException: Returned if a servlet can’t retrieve the web context attribute representing the bookstore. This will occur if the database server hasn’t been
started.

Because you have specified an error page, you will see the message

The application is unavailable. Please try later.

If you don’t specify an error page, the web container generates a default page containing the message

A Servlet Exception Has Occurred

and a stack trace that can help you diagnose the cause of the exception. If you use errorpage.html, you will have to look in the server log to determine the cause of
the exception.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved. Legal Notices

Cookie Preferences | Ad Choices

You might also like