The JavaTM Web Services Tutorial
Home
TOC
Index
PREV TOP NEXT
Divider

The Example JSP Pages

To illustrate JSP technology, this chapter rewrites each servlet in the Duke's Bookstore application introduced in as a JSP page:

Table 13-1 Duke's Bookstore Example JSP Pages 
Function
JSP Pages
Enter the bookstore
bookstore.jsp
Create the bookstore banner
banner.jsp
Browse the books offered for sale
catalog.jsp
Put a book in a shopping cart
catalog.jsp and bookdetails.jsp
Get detailed information on a specific book
bookdetails.jsp
Display the shopping cart
showcart.jsp
Remove one or more books from the shopping cart
showcart.jsp
Buy the books in the shopping cart
cashier.jsp
Receive an acknowledgement for the purchase
receipt.jsp

The data for the bookstore application is still maintained in a database. However, two changes are made to the database helper object database.BookDB:

The implementation of the database helper object follows. The bean has two instance variables: the current book and a reference to the database enterprise bean.

public class BookDB {
  private String bookId = "0";
  private BookDBEJB database = null;

  public BookDB () throws Exception {
  }
  public void setBookId(String bookId) {
    this.bookId = bookId;
  }
  public void setDatabase(BookDBEJB database) {
    this.database = database;
  }
  public BookDetails getBookDetails() 
    throws Exception {
    try {
      return (BookDetails)database.
          getBookDetails(bookId);
    } catch (BookNotFoundException ex) {
      throw ex;
    } 
  }
  ...
}
 

Finally, this version of the example contains an applet to generate a dynamic digital clock in the banner. See Including an Applet for a description of the JSP element that generates HTML for downloading the applet.

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

  1. In a terminal window, go to docs/tutorial/examples/web/bookstore2.
  2. Run ant build. The build target will spawn any necessary compilations and copy files to the docs/tutorial/examples/web/bookstore2/build directory.
  3. Make sure Tomcat is started.
  4. Run ant install. The install target notifies Tomcat that the new context is available.
  5. Start the PointBase database server and populate the database if you have not done so already (see Accessing Databases from Web Applications).
  6. Open the bookstore URL http://localhost:8080/bookstore2/enter.

See Common Problems and Their Solutions and Troubleshooting for help with diagnosing common problems.

Divider
Home
TOC
Index
PREV TOP NEXT
Divider

This tutorial contains information on the 1.0 version of the Java Web Services Developer Pack.

All of the material in The Java Web Services Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.