|
FAQ
History |
|
Search
Feedback |
The Example Servlets
This chapter uses the Duke's Bookstore application to illustrate the tasks involved in programming servlets. Table 3-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 for the Duke's Bookstore application is located in the
<INSTALL>/j2eetutorial/examples/web/bookstore1directory created when you unzip the tutorial bundle (see About the Examples).To deploy and run the example:
- In the IDE, mount the filesystem
<INSTALL>/j2eetutorial/examples/web/bookstore1.- Expand the
bookstore1node.- Right-click the
WEB-INFdirectory and choose Deploy.- Set up the PointBase database as described in Accessing Databases from Web Applications.
- Open the bookstore URL
http://localhost:80/bookstore1/enter.To review the deployment settings:
Troubleshooting
Because we have specified an error page, you will see the message
The application is unavailable. Please try later, when an exception occurs. You will have to look in the application server's log to determine the cause of the exception. The log file is <S1AS7_HOME>/domains/domain1/server1/logs/server.log. You can view the log in the application server administration tool as follows:Here are the exceptions that can be returned and their causes:
UnavailableException--Returned if a servlet can't retrieve the Web context attribute representing the bookstore database. This will occur if the PointBase server hasn't been started. In the log you will see the following:
12/Feb/2003:12:28:14] INFO ( 4944): CORE3282: stdout: Couldn't create connection.SQL-server rejected establishment of SQL-connection. PointBase.
[12/Feb/2003:12:28:14] INFO ( 4944): CORE3282: stdout: Couldn't create databaseCouldn't open connection to database: SQL-server rejected establishment of SQL-connection. PointBase.If you have the database server running but the application server can't communicate with it due to firewall interference, then you will see the following error:
[12/Feb/2003:16:15:14] INFO ( 1952): CORE3282: stdout: Couldn't create connection.nullouldn't open connection to database: null
[12/Feb/2003:16:15:14] INFO ( 1952): CORE3282: stdout: Couldn't create databaseCIf you have not defined a data source that references the PointBase database (see Defining a Data Source in Sun ONE Application Server 7), you will see the following:
[13/Feb/2003:10:32:23] INFO ( 3128): CORE3282: stdout: Couldn't create connection.BookDB not foundBookNotFoundException--Returned if a book can't be located in the bookstore database.This will occur if the PointBase database server has crashed.BooksNotFoundException--Returned if the bookstore data can't be retrieved. This will occur if the PointBase database server has crashed.
|
FAQ
History |
|
Search
Feedback |
All of the material in The J2EE Tutorial for the Sun ONE Platform is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.