The JavaTM Web Services Tutorial
Home
TOC
PREV TOP NEXT

The Example Servlets

This chapter uses the Duke's Bookstore application to illustrate the tasks involved in programming servlets. Table 1 lists the servlets that handle each bookstore function. 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 shows you how to track session information.

Table 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
Receive an acknowledgement for the purchase
ReceiptServlet

The data for the bookstore application is maintained in a database and accessed through the helper class database.BookDB. The database package also contains the class BookDetails which represents a book. The shopping cart and shopping cart items are represented by the classes cart.ShoppingCart and cart.ShoppingCartItem.

The source for the bookstore application is located in the docs/tutorial/examples/web/bookstore1 directory created when you unzip the tutorial bundle (see Running the Examples). To build, deploy, and run the example:

  1. Go to the examples directory and build and deploy the example by running ant. This runs the default ant target deploy which depends on the build target. The build target will spawn any necessary compilations and copy files to the docs/tutorial/examples/web/bookstore1/build directory. The deploy target copies the bookstore1 context file to <JWSDP_HOME>/webapps as described in Running Web Applications.
  2. Start the Pointbase database server (see Accessing Databases from Web Applications).
  3. Start or restart Tomcat.
  4. Open the bookstore URL http://localhost:8080/bookstore1/enter.

Troubleshooting

Common Problems and Their Solutions lists some reasons why a Web client can fail. In addition, Duke's Bookstore returns the following exceptions:

Since we 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 diagnose the cause of the exception. If you use the errorpage.html, you will have to look in the Web container's log to determine the cause of the exception. Web log files reside in the directory <JWSDP_HOME>/logs and are named jwsdp_log.<date>.txt.

Home
TOC
PREV TOP NEXT