A Shopping Cart Scenario


The shopping cart scenario presented in this chapter is a simplified online produce store. Customers select produce items to add to their shopping cart, and then move through a series of forms to purchase the items. Figure 7.1 shows that the application architecture combines JSP with servlets and JavaBeans[1]. Building simple Web applications using JSP alone is possible, of course, but significant business applications require all three.

click to expand
Figure 7.1: It is possible to build simple Web applications using JSP alone. However, significant business applications require Java servlets, JavaBeans, and JavaServer Pages.

Figure 7.2 shows the model-view-controller (MVC) pattern, which partitions applications into separate data management (model), presentation (view), and control components[1]. It underlies most modern graphical user interfaces. The partitioning encourages independent evolution and reuse of the separate components. You can also apply the MVC pattern to Web applications. JavaServer Pages most appropriately implement the presentation part of a Web application. JavaBeans encapsulate the services that supply content to a Web site and simplify passing data between the components of the architecture. Servlets function best as controllers and mediators routing user requests and application messages, updating application data, and driving the application workflow.

click to expand
Figure 7.2: Model-view-controller architecture; JSP architectures can be modeled using the MVC pattern.

Technologies such as JSP encourage certain designs, but don’t enforce them. For instance, all the code that might be put in a servlet or bean could be part of a single, certainly very confusing, JSP page. The JSP specification permits such designs. Conversely, anything a JSP page can do, a servlet can also do, so you can build a working architecture that ignores JSP. The adoption of a design pattern, however, implies certain design practices and choices. Design patterns generalize the collective wisdom of other developers. Developers capitalize on these lessons when they adhere to design patterns. If you use the MVC pattern, then the pattern implies that you should not mix presentation elements with control or data elements. Stated more specifically, you should not print HTML from a controller component (servlet) or imbed control elements in a presentation component (JSP). You should limit the Java in a JSP page to communication with the control and data components. Finally, if the data model for your application is at all complex (and it would be in any realistic business application), then you should not imbed data and computation services in either the control component or the view component. Instead, you should encapsulate such business in worker components (JavaBeans).

[1]Bollinger, Gary and Bharathi Natarajan, “Build an E-Commerce Shopping Cart,” Reprinted from Java Pro magazine with permission from Fawcette Technical Publications, Inc., 913 Emerson Street, Palo Alto, CA 94301-2415. Copyright 2000 by Fawcette Technical Publications, Inc. All rights reserved.




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