Sun Java System Application Server 

Samples Index

Duke's Bookstore Sample Application

The Duke's Bookstore sample application illustrates the tasks involved in programming using Java Server Pages (JSP). This application allows users to retrieve available books from a database table, displays details of the book, add and remove books to a shopping cart and check out the books. The Duke's Bookstore implements the Model-View-Controller design pattern and database helper object for accessing database.

The Bookstore sample and its associated files are in the install_dir/samples/webapps/apps/bookstore directory:

Building, Deploying, and Running the Application

The general instructions for building, deploying, and running sample applications are provided in Building, Deploying, and Running Sample Applications. In reading this document, use the following application-specific variables for this application:

Follow this general procedure:

  1. Build the Application. The build file, build.xml, is in the app_dir directory.
  2. Deploy the Application. If you deploy using Admin Console, you must register resources, as described below.
    Note: The first time you run asant deploy, it will prompt you for your Application Server host name, administration port, administration user and password and cluster name. The script will save these values in a properties file, and running it subsequently will get this information from the file.
  3. Run the application, as described below.

Registering Resources

When you deploy the application using asant, it will automatically configure the required JDBC resources. If however, you use Admin Console, you must create the JDBC resources manually. Follow these steps:

  1. Start your database server, if has not already been started.
  2. Create JDBC connection pool. Enter this command:
    asadmin create-jdbc-connection-pool
      --host adminhost --port adminport
      --user adminuser --password adminpassword
      --datasourceclassname datasource-classname
      --property User=dbusername:Password=dbpassword:url-property="jdbc-url"
      --target cluster-name
      bookstorePool

    You must escape ":" and "/" characters. If using Derby, the url-property would look something like this: jdbc\:derby\:\/\/localhost\:1527\/DerbyDB;create=true.

  3. Create JDBC resource. The JNDI name should be "jdbc/BooksDB" as specified in the deployment descriptor. Enter this command:
    asadmin create-jdbc-resource
      --host adminhost --port adminport
      --user adminuser --password adminpassword
      --connectionpoolid  bookstorePool
      jdbc/BooksDB

For more information on using Derby, see Using the Derby Database with Sample Applications.

Running the Sample Application

After you have built and deployed the application, started the database server, and configured resrouces, you can run the sample application by entering the following URL in your web browser:

http://ws-host:ws-port/dukesbookstore/enter

Where ws-host is the hostname of web server with the load balancer plugin and ws-port is the port one which the web server is running.

The following images illustrate running the application.

Duke's Bookstore context root (home) page

Click on the "Start Shopping" link to continue.

Book Catalog Page

Click on book titles to add them to your shopping cart.

Shopping Cart Page

Now, stop the instance that served the request. For information on how to do this, see Running the sample Applications. After the instance is shut down completely, click on the "Check Out" link. The second instance will retreive your shopping cart contents and then the application will display the correct purchase amount.


On the cashier page, click on the submit button to check out.

Troubleshooting

If you have problems when running the application, try the following:


Copyright © 2006 Sun Microsystems, Inc. All rights reserved.