Online grocery store


Published on

This is the project report of online grocery store.

Published in: Education
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Online grocery store

  1. 1. Online Grocery Store A SUMMER TRAINING PROJECT REPORT Submitted by- Kavita Sharma In partial fulfillment for the award of the degree Of BACHELOR OF TECHNOLOGY in Branch: INFORMATION TECHNOLOGYANSAL INSTITUTE OF TECHNOLOGY Affliated toGURU GOBIND SINGH INDRAPRASTHA UNIVERSITY, DELHI August 2
  2. 2. ABSTRACTAn online Grocery Store permits a customer to submit online orders foritems and/or services from a store that serves both walk-in customers andonline customers. The online Store system presents an online display ofall the items they want to sell. This web based application helpscustomers to choose their daily needs and add products to their shoppingcart. Customers provides their complete detail of address and contactand they get their chosen products in their home.This Web application saves lots of time of customers.
  4. 4. LIST OF TABLES1. Customer Table2. Product Table3. Category Table4. Order_Product Table5. Customer Order Table
  5. 5. Introduction to ServletsObjectiveServlet technology was the original Java based solution for web developmenthowever due to the problems of maintaining the HTML within the Java codethey were never a great success. JSP was the solution to this. However as wewill see later there is still a place for Servlets in Java Server development.This topic looks at the architecture of a Servlet and how to go about writingone.Just What is a Servlet ?A Servlet is quite simply a java class that adheres to the general model of aServlet as defined by the Servlet API. A Servlet Container, also known as aServlet Enginetranslates requests from whatever protocol is being used intoobjects that the Servlet understands, and also gives the Servlet an object whichit can use to send a response. This container is also responsible for managingthe lifecycle of a Servlet.Now we have already met the idea of a JSP Container which manages JSPexecution. In fact the JSP Container is only responsible for the rewriting of aJSP page to a Servlet and then allows the Servlet Container handle the actualexecution.The Servlet LifecycleServlet containers are responsible for handling requests, passing that request tothe Servlet and then returning the response to the client. The actualimpementation of the container will vary from program to program but theinterface between Containers and Servlets is defined by the Servlet API muchin the same way as there are many JSP Containers all adhering the to JSPSpecification.
  6. 6. The basic lifecycle of a Servlet is, The Servlet Container creates an instance of the Servlet. The Container calls the instances init() method. If the Container has a request for the Servlet it will call the instances service() method. Before the instance is destroyed the Container will call the destroy() method. Finally the instance is destroyed and marked for garbage collection. Typically the init() method is only called once and then the service()method is called repeatedly for each request. This is much more efficient than executing inti(),service(), destroy() for each request. What happens, you may ask yourself, when a service() method is still executing when the Container receives another request ? Typically this will involve the creation of another program execution thread. In practice, Servlet Containers create a pool of threads to which incoming requests are generally allocated.A Basic ServletA Servlet is defined by the javax.servlet.Servlet interface. There is also aGenericServletabstract class which provides a basic implementation of the Servletinterface. However for this discusssion we will only look at the HttpServlet classwhich extends the GenericServletclass. When you come to write a Servlet it will bethis class that you are most likely to extend.The service() methodThe service() method is implemented by the HttpServlet as a dispatcher of HTTPRequests and therefore should never be overridden. When a request is made the
  7. 7. service()method will determine the type of request (GET, POST, etc) and dispacthit to the appropriate method (doGet(), doPost(), etc). For the most part you will beoverridding doGet()and the doPost() methods. These have message signaturessimilar to,protected void do Post(HttpServletRequest request, HttpServletResponse response) throws ServletException, already know the two objects HttpServletRequest and HttpServletResponseasthese are just the implicit objects request and response and can be manipulated inexactly the same way within the body of the doGet(), doPost()methods.The init() methodThe init() method is executed when the Servlet is first instantiated. The Servletcontainer will pass an object of type ServletConfig to the method so that containerspecific configuration data can be stored by that Servlet instance for leter use.Not every Servlet requires that the init() method do something. The type of workcarried out by this method can include such activities as initiating databaseconnections, establishing default values or instantiating JavaBeans. If your Servletdoesnt require any kind of initialiation activity then dont include an init() methodin your ServletThe destroy() methodYou can assume that at any given time the Servlet container will decide to removethe Servlet. This might occur if the Container needs to free some memeory or theServlet hasnt been requested for some time. The destroy() method is called prior toremoving of the Servlet so you can use this method for any clean up activity thatmay be required; releasing database connections etc.
  8. 8. Introduction to JSPJava Server Pages or JSP for short is Suns solution for developing dynamic websites. JSP provide excellent server side scripting support for creating databasedriven web applications. JSP enable the developers to directly insert java code intojsp file, this makes the development process very simple and its maintenance alsobecomes very easy. JSP pages are efficient, it loads into the web servers memoryon receiving the request very first time and the subsequent calls are served within avery short period of time.In todays environment most web sites servers dynamic pages based on userrequest. Database is very convenient way to store the data of users and otherthings. JDBC provide excellent database connectivity in heterogeneous databaseenvironment. Using JSP and JDBC its very easy to develop database driven webapplication.Java is known for its characteristic of "write once, run anywhere." JSP pages areplatform independent. Your port your .jsp pages to any platform.The Components of JSPsJSP syntax is almost similar to XML syntax. The following general rules areapplicable to all JSP tags.1. Tags have either a start tag with optional attributes, an optional body, and amatching end tag or they have an empty tag possibly with attributes.2. Attribute values in the tag always appear quoted. The special strings ' and" can be used if quotes are a part of the attribute value itself.
  9. 9. Everything in a JSP page can be divided into two categories:1. Elements that are processed on the server2. Template data or everything other than elements, that the engine processing theJSP engines.Element data or that part of the JSP which is processed on the server, can beclassified into the following categories:1. Directives2. Scripting elements3. Standard actionsBenefits of JSPOne of the main reasons why the JavaServer Pages technology has evolved intowhat it is today and it is still evolving is the overwhelming technical need tosimplify application design by separating dynamic content from static templatedisplay data. Another benefit of utilizing JSP is that it allows to more cleanlyseparate the roles of web application/HTML designer from a software developer.The JSP technology is blessed with a number of exciting benefits, which arechronicled as follows:1. The JSP technology is platform independent, in its dynamic web pages, its webservers, and its underlying server components. That is, JSP pages perform perfectlywithout any hassle on any platform, run on any web server, and web-enabledapplication server. The JSP pages can be accessed from any web server.
  10. 10. 2. The JSP technology emphasizes the use of reusable components. Thesecomponents can be combined or manipulated towards developing more purposefulcomponents and page design. This definitely reduces development time apart fromthe At development time, JSPs are very different from Servlets, however, they areprecompiled into Servlets at run time and executed by a JSP engine which isinstalled on a Web-enabled application server such as BEA WebLogic and IBMWebSphere
  11. 11. INTRODUCTION TO PROJECT Concepts:o Front-end developmento Web application project structureo Data modelingo Database connectivityo Session managemento Transactional business logico Client and server-side validationo Web application Security. Technologies:o HTML, CSS, and JavaScript technologieso Servlet and JavaServer Pages (JSP) technologieso The JavaServer Pages Standard Tag Library (JSTL)o Java Database Connectivity (JDBC) Development Tools:o NetBeans 6.9 IDEo GlassFish, a Java EE application server
  12. 12. o MySQL, a relational database management server (RDBMS) Designing the Application Welcome Page:- The welcome page is the websites home page, and entry point for the application. It introduces the business and service to the user, and enables the user to navigate to any of the four product categories. category page The category page provides a listing of all products within the selected category. From this page, a user is able to view all product information, and add any of the listed products to his or her shopping cart. A user can also navigate to any of the provided categories.
  13. 13. cart pageThe cart page lists all items held in the users shopping cart. It displays productdetails for each item, and tallies the subtotal for the items in the cart. From thispage, a user can:Clear all items in his or her cart(Clicking clear cart causes the proceed to checkout buttons and shopping carttable to disappear.)Remove item from the Shopping cart.Return to the previous category by clicking continue shoppingProceed to checkout
  14. 14. checkout pageThe checkout page collects information from the customer using a form. This pagealso displays purchase conditions, and summarizes the order by providingcalculations for the total cost.The user is able to send personal details over a secure channel.
  15. 15. Designing the Data ModelEntities of the data model:- 1. Customer 2. Category 3. Product 4. OrderCustomer Table:-Product Table:-Category Table:-
  16. 16. Order:- Connecting Application to the DatabaseThis part focuses on database connectivity of our application to the database, addthe data to the different tables. Then, we need to setup connection pool and datasource on the Glassfish server. We need to retrieve data of category and producttable in our application JSP pages.Adding data to the Category table:-Adding data to the Product table:-
  17. 17. Creating a connection poll and Data source:- 1. Click the New File button in the IDEs toolbar 2. Select the GlassFish category, then select JDBC Resource and click Next. 3. Enter details to set up the data source
  18. 18. 4.Click Next. In Step 4, Add Connection Pool Properties, specify the followingdetails: o Datasource Classname: com.mysql.jdbc.jdbc2.optional.MysqlDataSource o Resource Type: javax.sql.ConnectionPoolDataSource o Description: (Optional) Connects to the project database5.Click Finish. The wizard generates a sun-resources.xml file for the project thatcontains all information required to set up the connection pool and data source onGlassFish. The sun-resources.xml file is a deployment descriptor specific to theGlassFish application server. When the project next gets deployed, the server willread in any configuration data contained in sun-resources.xml, and set up theconnection pool and data source accordingly. Note that once the connection pooland data source exist on the server, your project no longer requires the sun-resources.xml file.Quering the Database from JSP:-Setting Context Parameters:-This section demonstrates how to configure context parameters for the application,and how to access parameter values from JSP pages. The owner of an applicationmay want to be able to change certain settings without the need to make intrusivechanges to source code. Context parameters enable you application-wide access to
  19. 19. parameter values, and provide a convenient way to change parameter values from asingle location, should the need arise.Setting up context parameters can be accomplished in two steps: 1. Listing parameter names and values in the web deployment descriptor 2. Calling the parameters in JSP pages using the initParam objectyou create context parameters for the image paths to category and product imagesused in the project. Begin by adding the provided image resources to the project,then perform the two steps outlined above. 1.Import the img folder into the project. the img folder, then in the IDEsProjects window, paste the folder into the projects Web Pages node. Open the projects web deployment descriptor. In the Projects window, expand the Configuration Files node and double-click web.xml. Click the General tab, then expand Context Parameters and click the Add button. In the Add Context Parameter dialog, enter the following details: o Parameter Name: productImagePath o Parameter Value: img/products/
  20. 20. 1. Click OK. 2. Click the Add button again and enter the following details: o Parameter Name: categoryImagePath o Parameter Value: img/categories/3. Click the XML tab to view the XML content that has been added to the deployment descriptor. The following <context-param> entries have been added:4. <context-param>5. <description>The relative path to product images</description>6. <param-name>productImagePath</param-name>7. <param-value>img/products/</param-value>8. </context-param>9. <context-param>10. <description>The relative path to category images</description>
  21. 21. 11. <param-name>categoryImagePath</param-name> 12. <param-value>img/categories/</param-value> </context-param>Accessing database in index page:- 1. In the Projects window, double-click the index.jsp node to open it in the editor. 2. At the top of the file, before the first <div> tag, place your cursor on a blank line, then type db and press Ctrl-Space. In the code-completion pop-up window that displays, choose DB Query and write<sql:query var="categories" dataSource="jdbc/myaffablebean"> SELECT * FROM category</sql:query> 3. Then access, the category database using jstl for each loop, by using following code.<div id="indexRightColumn"> <c:forEach var="category" items="${categories.rows}"> <div class="categoryBox">
  22. 22. <a href="category.jsp?${}"> <span class="categoryLabelText">${}</span> <img src="${initParam.categoryImagePath}${}.jpg"style="height:120px; width:180px;" alt="${}"> </a> </div> </c:forEach> </div>Accessing database in category page:-Three aspects of the category page need to be handled dynamically. The leftcolumn must indicate which category is selected, the table heading must displaythe name of the selected category, and the table must list product details pertaining
  23. 23. to the selected category. In order to implement these aspects using JSTL, you can follow a simple, 2-step pattern:1. Retrieve data from the database using the JSTL sql tag library.2. Display the data using the JSTL core library and EL syntax.3. In the Projects window, double-click the category.jsp node to open it in the editor.4. Add the following SQL query to the top of the file.<sql:query var="categories" dataSource="jdbc/myaffablebean"> SELECT * FROM category</sql:query>5.Between the <div id="categoryLeftColumn"> tags, replace the existing staticplaceholder content with the following <c:forEach> loop.<div id="categoryLeftColumn"> <c:forEach var="category" items="${categories.rows}"> <c:choose> <c:when test="${}"> <div class="categoryButton" id="selectedCategory"> <span class="categoryText">${}</span> </div> </c:when>
  24. 24. <c:otherwise> <a href="category.jsp?${}" class="categoryButton"> <div class="categoryText"> ${} </div> </a> </c:otherwise> </c:choose> </c:forEach></div> 5. Click on run project. Session management in online Store:- Every e-commerce application that offers some form of shopping cart functionality needs to be able to remember user-specific data as users click through the website. Unfortunately for you the developer, the HTTP protocol, over which communication on the Internet takes place, is a stateless protocol. Each request
  25. 25. received by your server is an independent piece of information that has no relationto previously received requests. Therefore, if a customer clicks a button to add anitem to his or her shopping cart, your application must take measures to ensure notonly that the state of the users cart is updated, but that the action doesnt affect thecart of another user who happens to be browsing the site at the same time.Handling session data:-Applications can manage user sessions with the HttpSession object. You can binduser-specific data to the HttpSession object, then access this data at a later stage.Both bind and access actions can be done from Java classes, as well as fromsession-scoped variables in EL expressions.The online store application uses the HttpSession object to identify users overmultiple requests. An HttpSession object is obtained using getSession() on a givenrequest:HttpSession session=req.getSession();For session management we have to to create shopping servlet and two java classes 1. Product class 2. Shopping cart classProduct class:-In the product class we set and get all the detail of the product like product_id,name, description, price, quantity.
  26. 26. Product class:-package shopping;/**** @author kavita*/public class product { String name; String description; int id; float price; int quantity;public product() {
  27. 27. name=""; description=""; price=0; quantity=0; }public void setname(String pname) { name=pname;}public String getname() { return name;}public void setdescription(String desc)
  28. 28. { description=desc;}public String getdescription() { return description;}public void setprice(float p) { price=p;}public float getprice() { return price;
  29. 29. }public void setid(int pid) { id=pid;}public int getid() { return id;}public void setquantity(int q) { quantity=q;}public int getquantity()
  30. 30. { return quantity;}}Shopping servlet:-Shopping servlet perform various operations on the cart- 1. Remove item from the cart. 2. Proceed to the check out. 3. Calculate annual amount of the customer 4. Manage session for each customerAfter processing of shopping servlet control is transfer to the registration page, inthe registration page customer can enter his complete detail for completeprocessing of his order.Registration page:-
  31. 31. Register page:-It contains following fields to enter:- 1. Name 2. Email 3. Address 4. Contact 5. Region
  32. 32. After filling registration page control is transfer to register servlet where it acceptsall the parameters of registration page and save it into the sql table customers.Confirmation Page:-Confirmation page generates a order reference number and order will startprocessing by the store admin. You can enjoy home delievery of your daily needsat your doorstep with in 30 minutesAdmin Login:-Admin login page provides a login page in which admin of the store has to enterhis login name and password and login successfully and view customers ordersdetail, and start processing their order.
  33. 33. when admin enters his username and password control is transfer to the servlet,servlet check given user name and password with the stored user name andpassword if it matches then admin will be redirected to the welcome page.If it does not matches then user is redirected to unsuccessful login pageAdmin Page:-