An E-Commerce Web Application For A Small Retail Store: Babatunde Julius Adewumi
An E-Commerce Web Application For A Small Retail Store: Babatunde Julius Adewumi
Special thanks to my supervisor, Ms. Pirjo Prosi for her support and patience
throughout this thesis project.
Thanks to Dr. Ghodrat Moghadampour for the knowledge I gained from him and
for pushing me to the extreme during his programming classes. I actually learnt a
lot from him. Also, thanks to Dr. Seppo Mäkinen and Dr. Jarmo Mäkelä for their
support.
VAASAN AMMATTIKORKEAKOULU
UNIVERSITY OF APPLIED SCIENCES
Information Technology
ABSTRACT
In recent times, it has become necessary for any business to have an online
presence in order to remain relevant and competitive. As a result of this necessity
many businesses, including small enterprises, now operate an e-commerce web
store so as to increase sales and attract new customers. Also, business owners do
not have to worry about finding a place to erect their stores and customers can
have unhindered access to a wide range of products at any time and anywhere in
the world.
The objective of this thesis project was to develop an e-commerce Java web
application for a small retail store where the store owner sells his/her products
online. The application allows the owner to manage products, customers, and
orders. Also, with the application customers make orders and pay for the ordered
products. The application uses PayPal Express Checkout as its payment solution.
In addition, the web store offers customers and visitors to the site an opportunity
to subscribe to an email list in order to get news about new products and special
offers. Lastly, the application sends an automatic email confirmation after
completing an order or subscribing to an email list.
The development of this application was carried out on Eclipse IDE using the Java
programming language. The database communication of the application was
implemented by using JPA and JPQL, and MySQL database was used to store the
application data. The application was structured according to the Model-View-
Controller (MVC) pattern. The model, the view and the controller layers were
implemented by using JavaBeans, JSPs, and Servlet API respectively. The
payment transaction of the application was carried out on PayPal Sandbox (testing
environment) with different NVP API operations.
ABSTRACT
1 INTRODUCTION .......................................................................................... 10
1.1 Background ............................................................................................. 10
1.1.1 Brief History of E-commerce ...................................................... 10
1.1.2 Types of E-commerce ................................................................. 11
1.1.3 Why E-commerce Website for Businesses? ............................... 11
1.2 Objective ................................................................................................. 11
1.3 Thesis Overview ..................................................................................... 12
2 RELEVANT TOOLS AND TECHNOLOGIES ............................................ 13
2.1 Java Programming Language .................................................................. 13
2.2 JDK and JRE ........................................................................................... 13
2.3 Java EE.................................................................................................... 13
2.4 HTML and CSS ...................................................................................... 14
2.5 Servlet API .............................................................................................. 14
2.6 JSP Technology ...................................................................................... 14
2.7 JavaMail API .......................................................................................... 15
2.8 MySQL ................................................................................................... 16
2.9 JPA and JPQL ......................................................................................... 16
2.10 Eclipse IDE ............................................................................................. 17
2.11 Apache Tomcat ....................................................................................... 17
2.12 Apache POI ............................................................................................. 17
2.13 PayPal Express Checkout ....................................................................... 18
3 ANALYSIS AND REQUIREMENTS ........................................................... 19
3.1 Application Description .......................................................................... 19
3.2 Quality Function Deployment (QFD) ..................................................... 19
3.3 Analysis Models...................................................................................... 21
3.3.1 Use Case Diagram ....................................................................... 21
3.3.2 Class Diagram ............................................................................. 23
3.3.3 Sequence Diagram ...................................................................... 24
3.3.4 Component Diagram ................................................................... 26
3.3.5 Deployment Diagram .................................................................. 27
4 DATABASE AND GUI DESIGN ................................................................. 29
4.1 Database Design...................................................................................... 29
4.2 GUI Design ............................................................................................. 30
4.2.1 Home Page .................................................................................. 30
4.2.2 Shopping Cart Page ..................................................................... 31
4.2.3 Email Subscription Page ............................................................. 32
4.2.4 Order Review Page ..................................................................... 33
4.2.5 Order Confirmation Page ............................................................ 34
4.2.6 Admin Login Page ...................................................................... 35
4.2.7 Admin Menu Page....................................................................... 36
4.2.8 Categories Page ........................................................................... 37
4.2.9 Add Category Page ..................................................................... 38
4.2.10 Products Page .............................................................................. 39
4.2.11 Add Product Page ........................................................................ 40
4.2.12 Email List Page ........................................................................... 41
4.2.13 Report Download Form............................................................... 42
4.2.14 Orders List Page .......................................................................... 43
4.2.15 Payments List Page ..................................................................... 44
5 IMPLEMENTATION .................................................................................... 46
5.1 Home Page .............................................................................................. 46
5.2 Subscription to Email List ...................................................................... 47
5.3 Add Product to the Shopping Cart .......................................................... 48
5.4 Update Item in the Shopping Cart .......................................................... 49
5.5 Remove Item from the Shopping Cart .................................................... 50
5.6 Remove all Items from the Shopping Cart ............................................. 50
5.7 Payment with PayPal Express Checkout ................................................ 51
5.7.1 SetExpressCheckout API Call..................................................... 51
5.7.2 GetExpressCheckoutDetails API Call......................................... 52
5.7.3 DoExpressCheckoutPayment API Call ....................................... 53
5.8 Sending Email ......................................................................................... 54
5.9 Admin Login ........................................................................................... 55
5.10 Add Category .......................................................................................... 56
5.11 Add Product ............................................................................................ 57
5.12 Download Reports in Excel Format ........................................................ 58
6 TESTING ....................................................................................................... 60
7 CONCLUSION .............................................................................................. 63
REFERENCES ...................................................................................................... 64
APPENDICES....................................................................................................... 66
7
LIST OF ABBREVIATIONS
EL Expression Language
MVC Model-View-Controller
1 INTRODUCTION
Before the advent of e-commerce and the internet, consumers had to visit the traditional
brick and mortar stores to purchase goods or services, and the sellers had to find a space
where they could sell their products, but due to the arrival of e-commerce and the
internet some decades ago shoppers do not have to visit these stores to make a purchase,
neither do the sellers have to find a place to locate their stores. In fact, buying and
selling without any form of e-commerce is unthinkable, complicated and cumbersome
to many these days /1/.
1.1 Background
Electronic commerce started in the 1960s when Electronic Data Interchange (EDI) was
used by companies to carry out their daily business transactions electronically. In 1979,
Michael Aldrich invented online shopping from which the term teleshopping was
coined. In 1990, Tim Berners-Lee invented the World Wide Web, and thereafter he was
able to establish communication between a Hypertext Transfer Protocol (HTTP) client
and a server through the internet, leading to the advent of Amazon and eBay in the
1990s. These two prominent online stores have revolutionized the e-commerce market
since their inception as more and more online shops spring up every day. /4/
11
In today’s business world, it has become inevitable for any small, medium or large
enterprise to have an e-business store. The following are some of the reasons a business
should have an online presence.
1.2 Objective
The aim of this thesis is to develop an e-commerce Java web application for a small
retail store, where the store owner (also called the administrator or admin) can sell
goods over the internet. In the application, the admin will be able to manage products,
12
customers, and orders, while the customers will be able to order and pay for products.
The payment transaction will be carried out on PayPal testing environment (PayPal
Sandbox). Also, the buyers will have the opportunity to subscribe to an email list in
order to get announcements about new arrivals and sales promotions. Furthermore, there
will be an email notification after completing an order or subscribing to an email list.
This thesis report contains seven chapters. Chapter 1 introduces the thesis work by
giving some background knowledge of what e-commerce is, a brief history of e-
commerce, reasons for operating an e-commerce web store and the objective of the
thesis work. Chapter 2 presents some discussions about the relevant tools and
technologies used to develop the e-commerce application. Chapter 3 deals with the
analysis and requirements carried out during the development process of the application.
Then chapter 4 deals with the database and Graphical User Interface (GUI) design for
the application. Chapter 5 focuses on the implementation of the application, while
chapter 6 presents the various tests carried out on the application, including the results
of these tests. Lastly, the conclusion part of the thesis is given in chapter 7.
13
This chapter presents some discussions about the relevant tools and technologies used to
develop the e-commerce web application. Some of the tools and technologies are Java
programming language, JDK and JRE, Java EE, HTML, CSS, JSP technology (EL and
JSTL), JavaMail API and MySQL. Others are JPA and JPQL, Eclipse IDE, Apache
Tomcat, Apache POI and PayPal Express Checkout.
This is the main programming language used to develop the application. The Java
Programming Language was formerly developed by Sun Microsystems as proposed by
James Gosling. It was first released in 1995. It runs on Mac OS, Windows, the different
versions of UNIX, and other platforms. Java is considered to be secure and robust. Also,
it is multithreading and platform independent (unlike C and C++). /5/
2.3 Java EE
The Java EE platform is a superset of the Java SE platform, and it provides a runtime
environment, technologies, and APIs for building and running enterprise web
14
applications. The Java SE platform contains the core APIs of the Java programming
language. All of the APIs in Java SE are also contained in Java EE. Some of the core
technologies and APIs provided only by the Java EE platform are Servlet APIs,
JavaMail API, JDBC, JSP, and JPA. /7/
HTML stands for Hyper Text Markup Language. It is used as the standard markup
language for building web applications and web pages. It was originally developed by
Tim Berners-Lee in 1991. HTML5 is the latest version of HTML. /8/
CSS stands for Cascading Style Sheet. It is used to style web pages for different kinds
of devices and screen sizes. It also saves a lot of time and stress since it can be used to
style multiple web pages simultaneously. Its latest version is CSS3. /9/
A servlet is a Java class used for extending the functionality of web servers by
providing dynamic contents for web applications. These servers are used for hosting
web applications and are accessed through a request-response model. The servlet API
consists of classes and interfaces for developing Java servlets and is a component of the
Java EE platform. /10/
The JSP tags have been in use prior to JSP 2.0 specification. These JSP tags are used to
insert Java code into a JSP. Using these tags in a JSP results in an awkward combination
of Java code and HTML, and, therefore, efforts should be taken to avoid this practice
unless when maintaining legacy web applications. Some of these tags are JSP scriptlet,
JSP expression, and JSP declaration. /12/
15
Expression Language (EL) and JSP Standard Tag Library (JSTL) were introduced with
the JSP 2.0 specification. EL is used to easily get access to data stored in JavaBeans
components, while JSTL consists of tags used to accomplish common tasks in JSP.
Some of the tasks supported by JSTL are iteration and conditionals, manipulation of
XML documents and internalization tasks. It is usually a best practice to use EL and
JSTL instead of the JSP tags in a JSP. EL has a more fancy and simple syntax than JSP
tags. With EL it is possible to access collections like lists and maps, and nested
properties. Also, EL has more functionality and can handle null values better than JSP
tags. /12/
This high-level API provides the possibility to automatically send an email using Java.
It is a platform-independent and protocol-independent framework, which depends on
the JavaBeans Activation Framework (JAF) API. The diagram in Figure 1 shows the
mechanism of how email works. When sending an e-mail, the message is first sent from
the mail client software to the mail server software using Simple Mail Transfer Protocol
(SMTP), which is the most commonly used protocol to send an e-mail. Thereafter, the
sender mail server utilizes SMTP to send the message to the recipient’s mail server
software. Lastly, the recipient’s mail client utilizes Post Office Protocol (POP) or
Internet Message Access Protocol (IMAP) to retrieve the email message from the
recipient’s mail server. /12/
16
2.8 MySQL
MySQL is a free, open source relational database management system (RDBMS) that
supports Structured Query Language (SQL). An RDBMS is a system used to manage
databases, and it is made up of tables containing columns and rows, where the tables are
related by keys. MySQL DBMS is the world’s most popular open source database
system and one of the most commonly used database systems for Java web applications.
It is one of the fastest RDBMS and it is easy to use. Also, it runs on almost all
platforms, such as Windows, Linux and OS X. /12/
Java Persistence API (JPA) provides an object-relational (O/R) mapping technique for
transforming between business objects and relational database. The three most
commonly used implementations of JPA are EclipseLink, Hibernate, and TopLink, with
EclipseLink as the reference implementation. As a result, EclipseLink was used to
implement JPA for this application. JPA runs on top of Java Database Connectivity
(JDBC) and saves the programmer time and stress of writing SQL queries and JDBC
code. In JPA, the business objects are referred to as entities. A JPA entity is a plain old
Java object (POJO) with JPA annotations. /12/
1. JPA has the option to automatically create database tables according to the
relationships between the business objects. /12/
2. No need to write JDBC and SQL code when using JPA. /12/
3. Conversion between objects and rows in a relational database is automatic when
using JPA. /12/
4. Based on the relationships between business objects, JPA can perform automatic
join operations. /12/
The Apache Tomcat is an open source web server and servlet container developed and
released by the Apache Software Foundation (ASF). It is an implementation of Java
Servlet, JavaServer Pages, Java Expression Language and Java WebSocket
technologies. Its latest version is Tomcat 8.0.45. /14/
Apache POI (Poor Obfuscation Implementation) is a Java API for reading and writing
Microsoft Excel files using Java programs. Also, it is utilized for reading and writing
Microsoft Word and Microsoft PowerPoint files using Java. It supports different file
formats, such as xsl, xlsx and docx. It is an open source API developed and released by
ASF. /15/
18
PayPal Express Checkout streamlines the checkout experience for buyers and still keeps
them on the seller’s website after completing a purchase. It allows buyers to make use
of their PayPal balance, bank account or credit card to make payment without any need
to enter delicate information. It is readily available in any country where PayPal is
accepted. /17/
19
Requirements analysis is one of the major tasks in software engineering, which is vital
to the success of a software development project. It involves the determination of the
requirements or functions of a software project /18/. The main task to perform before
analyzing requirements is requirements elicitation /19/.
The requirements for this application were gathered based on QFD. This is because
QFD prioritizes both explicit and implicit requirements for the software. Also, it focuses
on client satisfaction all through the development process /20/.
This application is divided into two parts – the home page and the admin page. The
home page is where customers (buyers) can order and pay for products, and optionally
subscribe to an email list while the admin page is where the admin can carry out
administrative tasks. The admin page is restricted and can only be accessed through
authentication provided by the Apache Tomcat servlet container. This means that all the
web resources in the admin page can only be accessed by an authorized user.
According to user needs and expectations, QFD prioritizes requirements into three types
– they are:
20
1. Normal requirements – These are must have requirements with priority level 1.
They are requirements that fulfill client satisfaction if present. /19/
2. Expected requirements – These are should have requirements with priority level
2. They are requirements that are not explicitly declared by the client but could
be a reason for customer dissatisfaction if not accomplished. /19/
3. Exciting requirements – These are nice to have requirements with priority level
3. They are needs that are beyond the scope of the project but could result in
client satisfaction when present. /19/
The requirements for this application as prioritized according to QFD are shown in
Table 1.
Normal Requirements
1. The home page of the application should display available products whose quantity is not less
than one.
2. Customers should be able to add products to a shopping cart.
3. Customers should be able to view products in the shopping cart.
4. Customers should be able to update product quantity in the cart.
5. Customers should be able to remove any product from the cart.
6. Customer should be able to empty all the products in the cart.
7. Customers should have an option to subscribe to an email list.
8. Customers should be able to checkout through PayPal Express Checkout payment solution on
Paypal Sandbox.
9. Customers should be able to view order confirmation after a successful order completion.
10. The admin should be authenticated in order to have access to the admin page of the application
to perform any administrative task.
11. The admin should be able to manage (add, update and delete) products and their categories.
12. The admin should be able to view the lists of products and categories.
13. The admin should be able to view the email subscribers’ list.
14. The admin should be able to view payment and order details.
15. The admin should be able to update order status.
16. The application should save all customer, product, order, payment and admin data on MySQL
database.
Expected Requirements
1. The application should display a friendly error message after a failed login by the admin.
21
2. The application should display a friendly error message after a failed or canceled payment
process.
3. The application should implement interactive graphical user interfaces (GUI).
4. An email confirmation should be sent to customers who subscribe to the email list.
5. An email confirmation should be sent to customers after a successful order completion.
6. The admin should be able to download email subscribers’ list, payments and orders reports in
MS excel format.
Exciting Requirements
1. The application should implement other payment methods, such as debit/credit card and
google checkout.
2. The application should also be available on mobile devices.
Modeling involves the designing of software systems before coding takes place.
Modeling plays an important role in any software development project. It guarantees the
completeness and correctness of a software system and the fulfillment of end-users’
expectations. In addition, modeling serves as the only reference point to cross-check
requirements before coding. /19/
A Unified Modeling Language (UML) based tool was used to model this application.
UML diagrams give both static and dynamic views of an application and it is well
suited for object-oriented languages like Java and C# /19/. The following sub-sections
present the UML diagrams used to model this application.
The use case diagrams for this application illustrate the interactions that exist between
users (actors) and use cases (actions) within the application. There are two actors
identified for this application – administrator (admin) and customer actors. As a result,
there are two use case diagrams for the software application – admin use case diagram
and customer use case diagram. The admin is the owner of the e-commerce store who
performs various administrative tasks such as add products, view orders, and update
order status while the customer is any individual who buys a product or products from
the online store.
22
Figure 2 shows the admin use case diagram. The diagram depicts how the admin
communicates with the application. More so, it shows all the actions that the admin can
perform on the application. As can be seen in the diagram, before any of these actions
could be executed the admin will have to login in order to be authenticated.
Figure 3 shows the customer use case diagram. It describes the different use cases that
can be executed by the customer on the e-commerce application. For the checkout
process using PayPal Express Checkout, the buyer will have to be authenticated on a
secured PayPal website.
23
A class diagram depicts the classes in a software system and how they interact with
each other. Also, the class attributes and functions are illustrated in a class diagram.
Figure 4 shows the class diagram for this application. It shows the relationships between
classes in the application and constraints applied to these relationships.
24
A sequence diagram gives a detailed visual description of how the various classes in a
system interact with each other. Also, it depicts the order in which different objects
exchange messages with one another in a system. The sequence diagrams for this
application are presented in the following sub-sections.
Figure 5 gives a detailed sequence of events needed for the admin to login to the admin
page of the application. After providing the login credentials on the admin login page,
the admin is authenticated through a form-based authentication method provided by the
Apache Tomcat web server. After a successful authentication process, the admin is
forwarded to the admin menu page, which contains links to several administrative
functions. However, if the authentication process fails, the admin is redirected to the
admin login page with displayed error message. For the remaining sequence diagrams
required for the administrative tasks, see Appendices.
25
The order sequence diagram is shown in Figure 6 below. On the home page of the
application where all available products are displayed, the customer clicks the add
product to cart link in order to add a product to the shopping cart. Then, the application
returns the customer to the home page either to add more products to the cart or to view
the shopping cart page. If the customer clicks the display shopping cart link, the
shopping cart page is displayed. The shopping cart page contains all the line items in the
cart and it is where the buyer can increase a line item quantity, remove a line item from
the cart, and empty the entire cart line items. If the buyer performs any of these
activities in the shopping cart, the application returns to the shopping cart to show the
necessary updates in the shopping cart. If the customer clicks the continue shopping link
on the shopping cart page, he/she is redirected to the home page of the application.
Furthermore, if the shopping cart is not empty and the buyer clicks the checkout with
PayPal link, he/she is forwarded to the PayPal login page. On the PayPal login page, the
customer login with his/her PayPal account credentials. If the login was successful, the
customer is forwarded to PayPal order summary page, which shows summary
information of all the ordered products, including the total price of the order. Otherwise,
the buyer is redirected to PayPal login page to show an appropriate error message. On
the PayPal order summary page, the customer clicks the continue link and is forwarded
to the application’s order review page where he/she can access the complete order link.
Now, when the buyer clicks the complete order link, the database handler retrieves
26
customer, order and payment data. The handler updates the customer data on the
database if the customer data already exists otherwise, it writes the data to the database.
The handler also writes the order and payment data to the database.
Lastly, after the handler performs the necessary operations on the database, the
customer is redirected to the order confirmation page to display order confirmation
message. Also, an e-mail confirmation is sent to the customer.
pattern used for structuring web applications. The MVC pattern makes coding, testing
and maintenance of an application easier and it is usually considered as a best practice.
As can be seen in Figure 7, the MVC pattern divides this application into three distinct
layers: the model, the view, and the controller. The model is the business layer of the
application, which contains the JavaBeans for the application. A JavaBean is simply a
plain old Java object (POJO) used to encapsulate data. The view represents the
presentation layer, which contains JSP files for displaying the various pages of the
application. The controller controls the flow of data between the model and the view. It
contains servlets for updating the model object and saving it to the database through the
database handler. The servlets also update the view for presentation when necessary. In
addition, the database handler consists of data access classes, which provide methods
for storing data in the database since the JavaBeans do not provide these methods.
The deployment diagram for this application is illustrated in Figure 8. The diagram
shows the configuration of the run-time hardware components (nodes) and the software
components running on those nodes. As can be seen in Figure 8, to deploy this web
28
application a database server, an application server, and computers with internet access
are needed. Also, backup servers are provided for the database and application servers.
Every web application needs to have an operational database to store its generated data.
More so, a simple and interactive Graphical User Interface (GUI) is one of the success
indicators of any web application project. This chapter presents the database and GUI
design for this e-commerce application.
MySQL database management system is the most popular database system for Java web
applications because of its speed, reliability, and flexibility. All the data generated by
this application are managed on MySQL database system. Figure 9 shows the Entity
Relationship Diagram of the application database. All the tables (except admin and
admin_roles) were generated by JPA based on the relationships that exist among the
JPA entities defined for the application, and these relationships are clearly evidenced in
the ER diagram. The admin and admin_roles tables were defined for authentication
purpose. The following numbered list gives a brief explanation of these tables.
Figure 9. ER diagram.
The user interfaces for this e-commerce web application were designed using HTML
and CSS. Also, some elements of HTML5 were used in designing the interfaces. The
following subsections present the descriptions of these interfaces.
The home page of this application is shown in Figure 10. It is the start page of the
application where all available products with a quantity greater than zero are displayed.
Also, customers or visitors to the e-commerce store can browse available products by
category. On this page, customers can add products to the shopping cart, and there is a
link provided to view products added to the shopping cart. More so, a link is provided
31
for customers and visitors to display and fill the email subscription form in order to
subscribe to an email list for special announcements and offers.
The shopping cart page of this online store application is as shown in Figure 11. This
page is accessed when a user clicks the view cart link to show the information of all the
products added to the shopping cart. On this page, the quantity of any product in the cart
can be changed and updated. Any product can be removed from the cart and the cart can
be emptied as well. There are links provided for browsing available products by
category and also to return to the home page of the application. In addition, the PayPal
check out button is displayed on this page if the shopping cart is not empty.
32
Figure 12 shows the email subscription page. This page is accessed when a user clicks
the subscribe to email list link to display the email subscription form where a user can
enter and submit the subscription information. The form does not accept null or empty
values. After a successful subscription process, the user is redirected to a confirmation
page which displays a confirmation message.
33
The order review page of this application is as shown in Figure 13. This page shows an
order review just before confirmation. It displays the customer’s shipping address, order
amount, currency and payment status of the order. A button is provided to confirm the
order.
34
Shown in Figure 14 is the order confirmation page of this application. This page
displays a confirmation message after a successful order process. It shows the
customer’s shipping information and the details of the payment.
35
Figure 15 shows the admin login page. This page presents the admin login form where a
user can enter and submit login credentials for authentication purpose. It is actually a
customized form for form-based authentication method provided by Apache Tomcat
servlet container. More so, it is not possible to enter null or empty string values on the
form. The page is displayed whenever a user tries to access the admin page of the
application which is restricted and can only be accessed by authorized users. If the
authentication fails the same page is displayed again but with an error message.
36
The admin menu page is shown in Figure 16 and it is displayed when a user has been
successfully authenticated. The page is the gateway to the administrative tasks for the
admin. The links for these tasks have been categorized so that they can be easily
accessible.
37
The categories page is the page for managing product categories for the e-commerce
store, and it is accessed by clicking the manage categories link on the admin menu page.
It is shown in Figure 17 below. All the product categories stored in the database are
displayed on this page, and each of these categories has links for displaying all its
products, editing its data and deleting it from the database. Also, at the top of the page
there is a link for displaying a form for adding categories.
38
The page for adding product categories is shown in Figure 18. The page displays the
add category form when an admin user clicks the link for adding a category on the
categories page. The form checks for null and empty string values, thus, it is not
possible to enter null or empty string values. The edit category form is basically the
same as the add category form, except that it contains editable data in its field.
39
Figure 19 shows the products page of this application. It is the page for managing
products of the online store and is accessed by clicking the manage products link on the
admin menu page. All products of the store are displayed on this page, and each of these
products has links for editing its data and deleting it from the database. Also, at the top
of the page there is a link for adding products.
40
The page for adding products is shown in Figure 20. The form on this page is displayed
when the link for adding products on the products page is clicked. Every input on this
form is checked for null and empty values. The edit product form is basically the same
as the add product form, except that it contains editable data in its fields.
41
The email list page is shown in Figure 21. The page is accessed by clicking the display
email subscribers list link on the admin menu page. It displays a list of all customers
and visitors to the web store who have subscribed to the email list for special
announcements and offers.
42
Figure 22 shows the report download form, which is accessed by clicking the download
report link on the admin menu page. The user chooses the report to be downloaded,
enters start and end dates in the given format, and clicks the download button to
download the chosen report in excel format. An appropriate error message is displayed
if a wrong date format is entered.
43
The orders list page is shown in Figure 23. The page is displayed when an admin user
fills and successfully submits the orders report form. The page displays a list of all
orders requested in accordance with the start and end dates entered on the orders report
form. Also, it is possible to view details of an order by clicking the view details button.
Lastly, the status of the order can be updated on the order details page.
44
The diagram in Figure 24 is the payments list page of this online retail store application.
The page is accessed by filling and submitting the payment report form correctly. The
page displays a list of all payment transactions in accordance with the start and end
dates entered.
45
5 IMPLEMENTATION
This application was implemented as a JPA application, thus, the database tables used
by the application were automatically generated by JPA. As earlier shown in the
component diagram of Figure 7 of chapter 3, the application was structured according to
the MVC pattern. This pattern aims to separate the user interface logic from the
business logic. Also, this pattern helps to create well defined and organized web
applications with efficient code reuse and multiple views.
The home page of the application displays all the available products in the store. In
Code Snippet 1, the getProducts helper method is called to retrieve all product data
stored in the database. Also, shown in the code snippet is the implementation of the
getProducts method, which calls the getEntityManagerFactory static method in order to
establish a connection to the database. Then a Java Persistence Query Language (JPQL)
is written to query the database to return a list of all available products in the database.
47
try {
products = q.getResultList();
if (products == null || products.isEmpty())
products = null;
} finally {
em.close();
}
return products;
}
if (!ValidatorUtil.checkParam(firstName)
|| !ValidatorUtil.checkParam(lastName)
|| !ValidatorUtil.checkParam(email)) {
message = "No field can be empty";
request.setAttribute("message", message);
url = "/emailSubscription/index.jsp";
} else if (!ValidatorUtil.checkEmail(email)) {
request.setAttribute("emailError", "email not in the right format");
url = "/emailSubscription/index.jsp";
} else {// No two email address can be the same in the database.
if (DBEmail.emailExists(email)) {
String emailMessage = "This email address already exist. "
+ "<br> Kindly provide another email address.";
request.setAttribute("emailMessage", emailMessage);
url = "/emailSubscription/index.jsp";
} else {
DBEmail.addEmailSubscriber(emailSubscriber);
// Prepare the confirmation email message
String recipient = email;
String sender =
this.getServletContext().getInitParameter("custServEmailAddress");
String subject = "Email Subscription Confirmation";
String body = "<p>Hello "
+ emailSubscriber.getFirstName()
+ ",</p>\n\n"
+ "<p>Thank you for subscribing to our email list."
+ " We will send you news about our new prod-
ucts and special offers.</p>\n\n"
+ "<p>Sincerely, </p>\n" + "<p>T&T Team</p>\n\n";
try {
// Send email message.
EmailUtil.sendEmail(recipient, sender, subject, body,
bodyIsHTML);
} catch (MessagingException e) {
e.printStackTrace();
}
url = "/emailSubscription/confirmation.jsp";
}
}
return url;
}
In Code Snippet 3, the addCartItem method is called when a user clicks the add to cart
button on the home page of the application. In this method, a new instance of the Cart
49
class is created if the retrieved Cart object does not exist in the Session object. Then the
addCartItem method of the Cart class is called to add the product to the shopping cart
after all the necessary operations and checks. Lastly, the Cart object is saved into the
Session object and the user is redirected back to the home page of the application.
if (!code.isEmpty()) {
Product product = DBProduct.getProductByCode(code);
cart.addCartItem(product);
}
session.setAttribute("cart", cart);
return "/index.jsp";
The updateCartItem method in Code Snippet 4 is responsible for updating the quantities
of items in the shopping cart. The code and quantity parameters are first retrieved from
the Request object, and the Cart object retrieved from the Session object. After all the
necessary operations and checks, the updateCartItem method of the Cart class is called
to perform the necessary updates in the shopping cart, including item quantity.
50
int quantity;
Product product = DBProduct.getProductByCode(code);
try {
quantity = Integer.parseInt(qtyString);
if (quantity < 0 || quantity == 0) {
quantity = 1;
}
Code Snippet 4. Method for updating item quantity in the shopping cart.
Code Snippet 5. Method for removing item from the shopping cart.
Code Snippet 6 shows the implementation of the clearCart method. It is responsible for
removing all items from the shopping cart. It calls the clearCart method of the Cart class
to delete all items from the cart after all the necessary operations and checks.
51
Code Snippet 6. Method for removing all items from the shopping cart.
This e-commerce web store uses PayPal Express Checkout as its payment solution.
With this payment solution, the buyer does not enter any information as the buyer’s
details can be obtained from PayPal. For the purpose of testing, this application uses a
virtual testing environment called PayPal Sandbox, which mimics most of the features
of the PayPal production environment. In order to use the Sandbox server, a seller
(merchant) and a buyer test accounts were created. Three PayPal Name-Value Pair
(NVP) API operations were created to implement the Express Checkout payment
solution. The following subsections describe these API operations.
Code Snippet 7 shows the method used to implement the SetExpressCheckout API call.
This API call is used to initiate the payment transaction. When a buyer clicks the PayPal
check out button on the shopping cart page of the application, the
callShortcutExpressCheckout method is called. The checkoutDetails parameter of the
method contains the request-specific fields retrieved from the clicked button. The
returnURL parameter is the page on the e-commerce web store that PayPal redirects to
after a successful payment authorization, and the cancelURL is the page on the e-
commerce web store that PayPal redirects to if a buyer cancels the payment. From the
method implementation, the fields in the checkoutDetails parameter are used to
construct an NVP string, and then an HTTP POST request is sent to PayPal API server
by calling the httpCall method, which makes the SetExpressCheckout API call. Part of
the response to the API call is an acknowledgment status, which indicates a success or
failure with or without warning messages. Also, a token is returned as part of the
52
response. The token is a unique string used for identifying each transaction and in
making other API calls.
encode(checkoutDetails.get("currencyCodeType").toString()));
if (isSet(checkoutDetails.get("PAYMENTREQUEST_0_ITEMAMT")))
nvpstr.append("&PAYMENTREQUEST_0_ITEMAMT=").append(
encode(checkoutDetails.get("PAYMENTREQUEST_0_ITEMAMT")
.toString()));
if (isSet(checkoutDetails.get("PAYMENTREQUEST_0_TAXAMT")))
nvpstr.append("&PAYMENTREQUEST_0_TAXAMT=").append(
encode(checkoutDetails.get("PAYMENTREQUEST_0_TAXAMT")
.toString()));
if (isSet(checkoutDetails.get("shippingAmt")))
nvpstr.append("&PAYMENTREQUEST_0_SHIPPINGAMT=").append(
encode(checkoutDetails.get("PAYMENTREQUEST_0_SHIPPINGAMT")
.toString()));
if (isSet(checkoutDetails.get("handlingAmt")))
nvpstr.append("&PAYMENTREQUEST_0_HANDLINGAMT=").append(
encode(checkoutDetails.get("PAYMENTREQUEST_0_HANDLINGAMT")
.toString()));
if (isSet(checkoutDetails.get("shippingDiscAmt")))
nvpstr.append("&PAYMENTREQUEST_0_SHIPDISCAMT=").append(
encode(checkoutDetails.get("PAYMENTREQUEST_0_SHIPDISCAMT")
.toString()));
if (isSet(checkoutDetails.get("insuranceAmt")))
nvpstr.append("&PAYMENTREQUEST_0_INSURANCEAMT=").append(
encode(checkoutDetails.get("PAYMENTREQUEST_0_INSURANCEAMT")
.toString()));
//Make the API call.
return httpCall("DoExpressCheckoutPayment", nvpstr.toString());
Code Snippet 10 shows the method implementation for sending an email confirmation
to users after completing an order or subscribing to an email list. The method uses
methods and classes from the JavaMail API to automatically send email notifications.
The admin login process was implemented by the form-based authentication method
provided by Apache Tomcat container. Code Snippet 11 shows the authentication
configuration. As can be seen from the Code Snippet, all web resources in the admin
directory of the application are restricted and a user with manager role is being granted
authorization to access the restricted resources. Lastly, customized login and error pages
are defined for the authentication.
56
<security-role>
<description>owner</description>
<role-name>manager</role-name>
</security-role>
<security-constraint>
<!-- Restrict access to the URLs in the admin directory -->
<web-resource-collection>
<web-resource-name>Admin</web-resource-name>
<url-pattern>/admin/*</url-pattern>
</web-resource-collection>
<!-- Authorize the service and programmer roles -->
<auth-constraint>
<role-name>manager</role-name>
</auth-constraint>
</security-constraint>
<!-- Use form-based authentication to provide access -->
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/login.jsp</form-login-page>
<form-error-page>/login_error.jsp</form-error-page>
</form-login-config>
</login-config>
The method for adding category data into the database is shown in Code Snippet 12.
The method responds to the request sent when an authorized user clicks the add
category button on the add category form. The validity of the input data is checked by
calling the checkParm method. An appropriate error message is sent whenever
something goes wrong otherwise, the category data is inserted into the database by
calling the addCategory method.
57
return url;
}
Code Snippet 12. Method for adding category data into the database.
Code Snippet 13 shows the method for adding product data into the database. The
method responds to the request sent when an admin user clicks the add product button
on the add product form. The method checks the validity of the entered data by calling
the checkParam method. An appropriate error message is sent whenever something goes
wrong otherwise, the product data is added into the database by calling the addProduct
method.
58
}
return url;
}
Code Snippet 13. Method for adding product data into the database.
One of the methods for downloading reports in Microsoft excel format is shown in
Code Snippet 14. The method uses classes and methods from the Apache POI API to
create the email subscribers report in excel format.
59
6 TESTING
Software testing is carried out on a software application mainly to detect software bugs
or missing requirements of the application. It involves the process of investigating and
evaluating a software product or application in order to make sure that its business and
technical requirements are fulfilled. For the purpose of testing, this application was
deployed and run on Apache Tomcat servlet container and accessed on a web browser.
For simplicity, the testing template in Table 2 was used for the testing.
1. Access home page of the Enter the home page URL of the The home page of the Pass.
application on a web browser.
application to view application is displayed with
available products. available products.
2. View available products by Click any of the category links on The products for the clicked Pass.
the home page.
category. category are displayed.
3. Check for empty data input Click the subscribe to email list on The application displays a Pass.
home page.
on the email subscription message prompt telling the
Enter the required data on the form
form. with one or more empty inputs and user to enter data in the empty
click the subscribe now button.
field(s).
4. Check for an existing email Enter an existing email address The application displays an Pass.
together with the other inputs data.
address in the email error message indicating that
Click the subscribe now button.
subscription list. the provided email address
already exists in the database.
5. Check for correct data Enter correct data inputs on the The application displays a Pass.
email subscription form and click
inputs on the email confirmation message with the
subscribe now.
subscription form. entered data. Also, an email
confirmation is sent to the
provided email address.
6. Add product to the Click the add to cart button on the The application remains on the Pass.
displayed product on the home
shopping cart. home page with the number of
page.
items in the cart updated and
shown on the top of the home
61
page.
7. View the shopping cart. Click the view cart link on the The shopping cart of the Pass.
home page of the application.
application is displayed with
its items.
8. Update an item quantity in Edit the quantity of an item in the The item quantity, its price Pass.
cart and click the update button.
the shopping cart. and the total price of all items
in the cart are updated
accordingly.
9. Remove an item from the Click the remove button of the The item is removed from the Pass.
item to be removed.
shopping cart. cart and the total price of all
items in the cart is updated
accordingly.
10. Clear all items from the Click the clear cart button. The cart is empty. Pass.
shopping cart.
11. Continue shopping from the Click the continue shopping link. The user is redirected to the Pass.
shopping cart page. home page of the application
to continue shopping.
12. Check out with PayPal. Click the PayPal check out button The application redirects to Pass.
on the shopping cart page.
the login page of PayPal.
13. Confirm order after a Click the confirm order button on The order confirmation page is Pass.
the order review page of the
successful payment displayed with details of the
application.
authorization on PayPal. transaction. Also, an email
order confirmation is sent to
the email address of the buyer.
14. Access the admin page of Enter the admin page URL of the The admin login page of the Pass.
application on a web browser.
the application to carry application is displayed.
administrative tasks.
15. Check for empty login data Click the login button with one The application displays a Pass.
empty field.
on the admin login form. prompt message telling the
user to enter data in the empty
field.
16. Check for incorrect login Enter the incorrect login details. The login form with an error Pass.
Click the login button.
credentials on the admin
62
17. Check for correct login Enter the correct login details. The admin menu page is Pass.
Click the login button.
credentials on the admin displayed.
login form.
18. Access the admin menu Click any of the menu links on the The appropriate page is Pass.
page.
items on the admin menu displayed.
page.
19. Check for empty data Enter the required data on the form The application displays a Pass.
with one or more empty inputs and
inputs on forms accessible message prompt telling the
submit the form.
by the admin. user to enter data in the empty
field(s).
20. Add/edit category/product. Enter the required data on the An appropriate page is Pass.
appropriate form and submit.
displayed to show the
added/edited category or
product.
21. Delete category/product. Click the appropriate delete button. The application displays an Pass.
appropriate page to confirm
the deleted category or
product.
22. Download report in excel Access the appropriate link to The application presents the Pass.
download the report.
format. report in an excel document.
63
7 CONCLUSION
The main objective of this thesis work was to develop an e-commerce Java web
application for a small retail store where the store owner manages products, customers,
and orders, while the customers make orders and pay for products. The application was
developed with the above-mentioned features.
One of the biggest challenges faced during the development of this software project was
how to implement JPA for the application. A lot of time and effort were invested in
learning and implementing JPA for this e-commerce application. Another challenge
faced was how to integrate PayPal Express Checkout NVP API operations for the
project. PayPal has a poor API integration documentation, especially API integration for
the Java programming language. This actually affected the flow of the application
development process as much time was used to learn and understand the NVP API
integration for Java. With these challenges and others not mentioned here, a lot of new
experience has been gained during the development process of this application.
Although all the requirements set out for the e-commerce web application have been
met, there are still areas to improve on. A mobile version can be developed for the
application so that users can have a better access to the application. Also, other online
payment methods like credit/debit card and bank payment methods can be implemented
for the application.
64
REFERENCES
/1/ Miva 2011. The History Of Ecommerce: How Did It All Begin? Accessed
15.07.2017. http://www.miva.com/blog/the-history-of-ecommerce-how-did-it-all-begin/
/6/ Stackoverflow 2017. What is the difference between JDK and JRE? Accessed
17.07.2017. https://stackoverflow.com/questions/1906445/what-is-the-difference-
between-jdk-and-jre
/7/ Evans, I. 2012. Differences between Java EE and Java SE - Your First Cup: An
Introduction to the Java EE Platform. Accessed 17.07.2017.
http://docs.oracle.com/javaee/6/firstcup/doc/gkhoy.html
/12/ Murach, J. & Urban, M. 2014. Murach’s Java Servlets and JSP. 3rd ed. Fresno
California. Mike Murach & Associates, Inc.
/14/ The Apache Software Foundation 2017. Apache Tomcat. Accessed 22.07.2017.
https://tomcat.apache.org/
/15/ The Apache Software Foundation 2017. Apache POI – the Java API for
Microsoft Documents. Accessed 23.07.2017. https://poi.apache.org/
65
APPENDICES