background image

The Example Servlets

<< Java Servlet Technology | Deploy and Run the Application using Ant >>
<< Java Servlet Technology | Deploy and Run the Application using Ant >>

The Example Servlets

The Example Servlets
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
tut-install/javaeetutorial5/examples/web/bookstore1/ directory, which is created when
you unzip the tutorial bundle (see
"Building the Examples" on page 70
).
Table 4­1
lists the servlets that handle each bookstore function. You can find these servlet
classes in
tut-install/javaeetutorial5/examples/web/bookstore1/src/java/com/sun/bookstore1/.
Each programming task is illustrated by one or more servlets. For example,
BookDetailsServlet
illustrates how to handle HTTP GET requests, BookDetailsServlet and
CatalogServlet
show how to construct responses, and CatalogServlet illustrates how to
track session information.
TABLE 4­1
Duke's Bookstore Example Servlets
Function
Servlet
Enter the bookstore
BookStoreServlet
Create the bookstore banner
BannerServlet
Browse the bookstore catalog
CatalogServlet
Put a book in a shopping cart
CatalogServlet
,
BookDetailsServlet
Get detailed information on a specific book
BookDetailsServlet
Display the shopping cart
ShowCartServlet
Remove one or more books from the shopping cart
ShowCartServlet
Buy the books in the shopping cart
CashierServlet
Send an acknowledgment of the purchase
ReceiptServlet
The data for the bookstore application is maintained in a database and accessed through the
database access class database.BookDBAO. The database package also contains the class Book
which represents a book. The shopping cart and shopping cart items are represented by the
classes cart.ShoppingCart and cart.ShoppingCartItem, respectively.
To deploy and run the application using NetBeans IDE, follow these steps:
1. Perform all the operations described in
"Accessing Databases from Web Applications" on
page 97
.
2. In NetBeans IDE, select File
Open Project Folder.
3. In the Open Project dialog, navigate to:
The Example Servlets
The Java EE 5 Tutorial · September 2007
100