The CustomerServlet


With the design issues of this scenario in mind, let’s look at the details of a sample application. For example, a CustomerServlet controls the application workflow by doing two things: it maintains state (the model) for a shopping cart component (implemented by a BasketBean class), and it routes client requests through a series of JSP pages.

The BasketBean

A BasketBean usually implements a simple data manager (model) for a shopping cart application. The BasketBean class provides a method to get the running total of a customer’s purchases and a method to update the contents of the basket. It maintains a running list of Product instances requested by the client in a hashtable keyed off the Stock Keeping Unit (SKU) number. Each Product instance stores four attributes: a product name, SKU number, price per pound, and the number of pounds purchased. A product is added only if the number of pounds is greater than zero.

The Pages

This simple shopping cart scenario supports a workflow with four stages and three JSP pages: Inventory.jsp, Purchase.jsp, and Receipt.jsp (see Figure 7.3)[1]. The sample application presents Inventory.jsp to new clients. Clients select produce by performing one or more updates to Inventory.jsp. After selecting produce for purchase, clients purchase the produce and the application presents Purchase.jsp. Finally, the client confirms the purchase, and the application presents Receipt.jsp.

click to expand
Figure 7.3: Shopping cart workflow; the shopping cart application moves through stages in an interactive workflow.

This JSP page mixes standard HTML with specialized JSP elements. The JSP specification calls the static HTML in a page-fixed template data and writes it essentially verbatim (certain substitutions based on quoting and escape conventions are still applied) into the http response stream. For example, the servlet framework writes the tag <HTML> unchanged to the response stream. Besides fixed template data, JSP pages can include directives, scripting elements, and actions. This simple Web store illustrates all three.




Electronic Commerce (Networking Serie 2003)
Electronic Commerce (Charles River Media Networking/Security)
ISBN: 1584500646
EAN: 2147483647
Year: 2004
Pages: 260
Authors: Pete Loshin

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net