|
Download
FAQ History |
|
API
Search Feedback |
The Example Servlets
This chapter uses the Duke's Bookstore application to illustrate the tasks involved in programming servlets. Table 15-1 lists the servlets that handle each bookstore function. Each programming task is illustrated by one or more servlets. For example,
BookDetailsServletillustrates how to handle HTTPGETrequests,BookDetailsServletandCatalogServletshow how to construct responses, andCatalogServletillustrates how to track session information.
The data for the bookstore application is maintained in a database and accessed through the helper class
database.BookDB. Thedatabasepackage also contains the classBookDetails, which represents a book. The shopping cart and shopping cart items are represented by the classescart.ShoppingCartandcart.ShoppingCartItem, respectively.The source code for the bookstore application is located in the
<INSTALL>/jwstutorial12/examples/web/bookstore1/directory created when you unzip the tutorial bundle (see Building and Running the Examples). A samplebookstore1.waris provided in<INSTALL>/jwstutorial12/examples/web/provided-wars/. To build, package, deploy, and run the example:
- Build and package the bookstore common files as described in Updating Web Applications.
- In a terminal window, go to
<INSTALL>/jwstutorial12/examples/web/bookstore1/.- Run
antbuild. This target will spawn any necessary compilations and copy files to the<INSTALL>/jwstutorial12/examples/web/bookstore1/build/directory.- Start Tomcat.
- Perform all the operations described in Accessing Databases from Web Applications.
- Run
antinstall-config. Theinstall-configtarget notifies Tomcat that the new context is available.- To run the application, open the bookstore URL
http://localhost:8080/bookstore1/bookstore.To deploy the application:
Troubleshooting
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 by runningantcreate-book-dbor if the database server hasn't been started or it has crashed.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 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 messageA Servlet Exception Has Occurredand a stack trace that can help diagnose the cause of the exception. If you useerrorpage.html, you will have to look in the server log to determine the cause of the exception. Web log files reside in the directory <JWSDP_HOME>/logsand are named jwsdp_log.<date>.txt.
|
Download
FAQ History |
|
API
Search Feedback |
All of the material in The Java(TM) Web Services Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.