Simple Shopping cart project

This is a simple JavaWeb project with Intellij IDEA, development environment using JDK1.8 and Tomcat8 as well as mysql database.

1. Preparation for project development:

  1. Create the Github repository
  2. Project framework building
  3. The project builds and synchronizes the repository
  4. Write the required business logic

2. Develop project solutions:

  1. The github repository belongs to the project repository
  2. The shopCartDB database is used to store the data required by the shopping cart project
  3. The annotation @webServlet is used for the HTTP request response
  4. Set up JSP + Servlet architecture technical framework, JSP page data rendering based on C tag and EL expression,

C Label introduction:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
Copy the code

According to JDBC direct connection technology, write database operation tool class to facilitate data storage, the code is as follows:

public class DBUtils { String url = null; String username = null; // Database name String password = null; // Database password String driverClass = null; Private static DBUtils db = new DBUtils(); / * * building database connection parameters * / private DBUtils () {try {url = "JDBC: mysql: / / localhost: 3306 / shopCartDb? useUnicode=true&characterEncoding=utf8"; username = "root"; password = "root123"; driverClass = "com.mysql.jdbc.Driver"; Class.forName(driverClass); } catch (Exception e) { e.printStackTrace(); Public Connection getConnection(){Connection conn = null; try { conn = DriverManager.getConnection(url, username, password); } catch (Exception e) { e.printStackTrace(); } return conn; } public static DBUtils getInstance(){ return db; }}Copy the code

3. Project Functions:

  1. registered
  2. The login
  3. Retrieve password
  4. List of goods
  5. Add shopping cart
  6. Shopping cart deletion
  7. Shopping cart quantity modification
  8. Shopping cart settlement

4. Job Content:

This project uses mysql database to store data, so the database structure required by the project is set up first. This project has user table, commodity table, shopping cart table, settlement table and other information. JSP + Servlet framework is used to provide HTTP request and response view capabilities to display the JSP pages required by the project. Register according to the response displayed on the registration page. According to fill in the registration of the account and password to login the system, and such as forgot password, according to the mail form of dynamic authentication code password back, password using tencent QQ services provided by the SMTP server for authentication code to send and receive operation, after the system into the display item list, using c label db incoming data for dynamic rendering, El expression for data value display, add shopping cart using Ajax request to add shopping cart, remove shopping cart technology, according to the added shopping cart list data, can change the number of shopping cart for settlement, shopping cart page data check box check mode. Multiple commodities can be settled together. Js technology is used to screen out specific commodities to be checked, and the final price settlement is carried out according to the quantity and unit price of the checked commodities. Thus complete a series of shopping cart technology implementation

5. Project Summary:

  1. JSP + Servlet combination framework development, coherent MVC framework
  2. Understand the c tag for data rendering and various powerful rendering capabilities, can be more reasonable dynamic display of complex data structure
  3. Rich learning markdown extended syntax, can more intuitive presentation of project introduction documents
  4. Reasonable use of JDBC direct connection technology, more familiar with the data add, delete, change and check operations
  5. Consolidate the basic knowledge of Java, and for the deficiency of additional learning, such as list structure and array structure application
  6. Familiar with Ajax technology, can use Ajax technology for GET and POST requests for data transmission and response

6. Some code screenshots:

  1. Item list code

  1. Shopping cart list code

  1. Settlement backend code

  1. Settlement list code

7. Project Effect:

  1. The login

  1. List of goods

  1. Shopping cart list

  1. The settlement list