You are on page 1of 7

Shopping Cart Project

This document presents a Java MVC architecture design for an online shopping cart application.
Diagram below illustrates the Model module, View module, and Controller module, the
connections between the modules, and the back-end database support as well. There are a
variety of ways to implement an online store. Many functionalities of an online store are not
included in this implementation such as customer information processing, shipping and handling
processing, accounting processing, and etc. We have simplified the implementation in order to
focus on the MVC design architecture so you will have a better picture of it. We divide the system
into three sub-systems which will be discussed in the following sections. The Diagram depicts the
overall MVC architecture of this DVD online store Web application.
The following topics are covered below:
Getting the software
Install and Configure the Database
Create a Database Instance
Create a Java Web Project
Run the Project
Getting the Software
Before you begin, make sure you have the following software installed on your computer:
1. NetBeans IDE 6.5
2. Java SE Development Kit (JDK) version 5.0 or higher
3. MySQL database
4. JDBC Driver for MySQL
Install and Configure the Database
Now I am assuming you install and configure the MySQL database, if not go to:
http://www.netbeans.org/kb/55/mysql.html and choose Installing and Configuring the Database
section
Create a Database Instance
Now that you have connected to the database, you can begin exploring how to create tables,
populate them with data, and modify data maintained in tables. This allows you to take a closer
look at the functionality offered by the Database explorer
1. Creat Mysql database test: Right-click on the MySQL Server at Localhost and select
Create Database. For New Database Name, enter test.
2. Create table products: Right-click on the Tables inside jdbc:mysql://localhost:3306/test
and select Create Table. For Table name, enter products. For more values you want to
insert, click on Add column. When you done, click OK.
3. Insert values on products: Right-click the product table you just create and select View
Data. Click on the button on top right hand side corner and enter values.
Creat a Java Web Project
So far you have database created and now you could create java web project to access to the
database.
1. Create table shoppingcarts: This process is same as create products table, but without
any values inserted.
2. Create java web project: From File>New Project, select Java Web>Web Application. Click
OK. For Project Name, enter shoppingCart. For the rest, The Wizard will guide you
through the procedure. Accept all default settings.
3. Create new JSP file: Right-click on shoppingCart project you just create and select
New>JSP. For JSP name, enter Displayshopping Cart and click OK. Add contents to it.
Repeat this procedure with new JSP called ShowConfirmation, ShowProductCatalog.
Code is attached at the end.
4. Create new java file: Right-click on the shoppingCart project and select New>Java. For
Java name, enter AddToShoppingCartServlet and click OK. Add contents to it. Repeat this
procedure with new java called CheckoutServlet, DVD, ProductDataBean,
RemoveItemServlet, ShoppingCart. Code is attached at the end.
5. Setup context.xml: Open up context.xml. Add content to it. Code is attached at the end.
6. Setup web.xml: Open up web.xml and select Servlets. Click Add Servlet Element on the
top right hand side corner. For Servlet Name, Servlet Class and URL Pattern, enter
addToShoppingCartServlet, cart.addToShopingCartServlet,
/servlet/addToShoppingCartServlet. Repeat this procedure with servlets of
removeItemServlet and checkoutServlet.
7. Insert welcome page: Select Pages and for Welcome Files, enter ShowProductCatalog.jsp.
Now we have web.xml set up and XML code is generated automatically.
8. Add library: Right-click on Libraries and select Add library. Select JSTL 1.1 and click Add
Library.
Run the Project
1. Build and Run the program
2. Enter quantity and Click on AddToCart
3. Check out

You might also like