Previous Next Contents Index


Inside the Online Bookstore Sample Application

This chapter describes the design, file components, and functionality of the online bookstore sample application.

The following topics are presented in this chapter:


Design Overview
The Online Bookstore sample application, which is shipped with NAS, simulates an Internet e-commerce site where customers can search for books, show details, add books to their shopping cart, place orders, and register for billing. Furthermore, bookstore managers can access information about customer usage and order status.

The user interface is a web browser that displays HTML pages and JavaServer pages. The application was designed to run on Windows NT. In addition, the application can access an Oracle8 database and an LDAP server such as Netscape Directory Server.

Application Model The Online Bookstore demonstrates the NAS application model by incorporating the following features:

Application Flow The flowchart on the following page summarizes the design of Online Bookstore. You can think of this application as a set of functional modules, each controlled by a servlet. This functional grouping is conceptual, not structural—a convenience for better understanding the application flow. This modular approach encourages parallel code development, through which different teams handle each design module at the same time, with minimal overlap.



Presentation Flow
The following sequence describes a typical user session with the Online Bookstore:

  1. From a web browser, the user navigates the Internet to reach the first page of the application, index.html.
  2. From index.html, users can follow two main branches: customers can click the Store Entrance image to display BookStore.jsp, and application administrators can click the Manager's Office image to invoke AdminServlet.
  3. As a typical user, a customer clicks the Store Entrance image. The application then displays the main customer page, BookStore.jsp.
  4. From the BookStore.jsp page, a customer can browse books by subject, search books by keyword, or add books to a shopping cart. Any of these tasks can be performed as an anonymous user. However, before placing an order or checking previous orders, a customer must sign in.
  5. Clicking the Sign In link invokes the Login servlet. This servlet causes the right side of the page to display the Customer Sign In form, a JSP named LoginForm.jsp.

  6. From the Customer Sign In form, customers can take either of two actions. Customers who previously registered can enter their email address and password, whereas new customers must click the Register here link.
  7. Clicking Register here invokes the Register servlet. This servlet causes the right side of the page to display the Registration form, a JSP named RegistrationForm.jsp.

  8. Regardless of whether a user is registered, the user can perform different types of searches from the left side of the page, using either the Quick Search table or the Explore table. These page elements invoke the SearchServlet.
  9. When a results page appears, users can click a book title hyperlink. Clicking a book title invokes the BookDetail servlet, which in turn displays a JSP of item details.
  10. If the book is of interest, the user presses a button to add the item to the shopping cart. This action invokes the CartServlet, which in turn displays a JSP of selected books. The displayed prices are calculated with the help of ShoppingCartBean.
  11. When the user is ready to buy the items in the shopping cart, the user presses the Place Order button. This action invokes the PlaceOrder servlet. This servlet uses the CashierBean to calculate the charges, then displays the charges using the ShowOrder JSP.
  12. The user can continue to navigate the application, searching for more books or checking previous orders, for example.
  13. Eventually, the user clicks the Logout hyperlink to invoke the Logout servlet.

Directory Structure
The sample application includes component files organized into the following directories.

Directory
Contents
account
The BookAccount bean and related files to support accounting and inventory.
cart
The Cart bean and related files to support the selection of books.
cashier
The Cashier bean and related files to support the buying of books.
custom
Files involved with customizing the look and feel of the user interface. This functionality is invoked using the Personalize button on the Bookstore JSP.
database
Helper classes and other code for connecting to the database.
images
GIF and JPG files used in the web pages.
jsp
JavaServer Pages
ldap
A java file and property file to control LDAP access.
ntv
The .gxr file (used in deployment) and various configuration files.
util
Java files helpful to application developers.

In addition, many servlet files reside at the same level as the previous directories. These servlets are described in the next section.


Servlets
This section describes the servlets used in the Online Bookstore. The servlets are listed in the approximate order they would be encountered during a typical session.

BookstoreServlet, called from index.html, displays the Bookstore JSP. This JSP is the main customer page. Several of the application's servlets are invoked from the Bookstore JSP.

LoginServlet is invoked from the Bookstore JSP. This servlet launches LoginForm.jsp, which in turn displays the Customer Sign In form. LoginServlet verifies a customer's email ID and password against records in the database, then saves this information into an HTTP session.

SearchServlet is invoked from the Bookstore JSP. This servlet implements logic for basic keyword searches, for detailed, form-based searches, and for browsing by categories. SearchServlet also launches the JSPs necessary to input the search criteria or to display the results.

BookDetailServlet is called from any book title link, as might appear in ShowBooks.jsp and BooksByCategory.jsp. The servlet validates the bookID parameter and launches BookDetails.jsp to display more information about the item.

CartServlet manages the addition, deletion, and modification of shopping cart items. This servlet is called by the "Shopping Cart" link on the Bookstore JSP, as well as by buttons labeled "Add to Shopping Cart" or "Delete from Shopping Cart." CartServlet launches either of two JSPs: DisplayCartItem.jsp or DisplayEmptyCart.jsp. The ShoppingCartBean EJB determines the items and prices that appear.

PlaceOrderServlet is invoked from the "Place Order" button on DisplayCartItem.jsp. The servlet checks the customer object saved in the session. If the customer is registered, then control passes to the CashierBean EJB, the order is processed, and the results appear by way of ShowOrder.jsp. If the customer is not registered, then control passes to RegisterServlet.

RegisterServlet launches RegistrationForm.jsp, in which customers enter personal information. When users submit their data, RegisterServlet connects to a database, inserts the data, and saves the information into an HTTP session. RegisterServlet is invoked under two circumstances: when the user clicks "Register Here" in the LoginForm JSP, or when the PlaceOrder servlet detects an unregistered user.

CheckOrdersServlet is invoked from the Bookstore JSP. When invoked by registered users, the servlet displays CheckOrders.jsp, which shows the user's previous orders, if any. When invoked by an administrator, the servlet displays ShowAllOrders.jsp, which shows orders from all customers.

AdminServlet, called from index.html, displays AdminLoginForm.jsp. This JSP form accepts a bookstore administrator's ID and password. AdminServlet passes this input to an LDAP server for authentication. If authentication succeeds, the servlet allows viewing of customer information on another JSP, ShowAllOrders.jsp.

LogoutServlet, invoked from the Bookstore JSP, implements the sign-out logic. LogoutServlet invalidates the customer's HTTP session and creates a new one.


EJB Functionality
The sample application contains three EJBs, and their database interactions are shown in the following figure.

ShoppingCartBean is a stateful session bean. It holds the book items chosen during the shopping session. The bean is stateful because the data it holds is unique to each client and must not be shared. CartServlet relies on ShoppingCartBean to display book information to the appropriate JSP. The CashierBean EJB calls ShoppingCartBean to obtain data needed when an order is placed.

BookAccountBean is an entity bean that controls the inventory of each book. Unlike the other beans, BookAccountBean is involved in transactions only with the database. In other words, this bean does not calculate data for display in JSPs. CashierBean passes to BookAccountBean a set of book IDs and the quantities sold for each. BookAccountBean then connects to the database and performs a global transaction, thereby reducing the book counts as needed.

CashierBean is a stateless session bean. It coordinates with ShoppingCartBean and BookAccountBean to process the customer's order. CashierBean encapsulates business logic, such as applying the necessary shipping fees and taxes. BookAccountBean then connects to the database and updates it using a global transaction.

 

© Copyright 1999 Netscape Communications Corp.