Design and Realization of a Shopping Mall Based on JavaWeb

1 Introduction

With the continuous development of Internet technology, e-commerce has become an important form of economic activity. As one of the representatives of traditional culture, native products play a very important role in the tourism industry. Therefore, combining local product sales with e-commerce and establishing a JavaWeb-based local product sales shopping mall will help expand the local product sales channels and promote the local product culture.

This thesis will introduce the design and implementation of a JavaWeb-based shopping mall for souvenir sales. First, we will introduce the requirements analysis of the mall, including aspects such as mall functions and user roles. Then, we will design the system architecture of the mall based on the MVC pattern, and describe the function and interaction process of each module in detail. Next, we will introduce the database design of the mall and the implementation of data access using JDBC API. Finally, we will verify the functionality of the mall by deploying it to a Tomcat server and testing its functional integrity and stability.

In short, through the introduction of this paper, readers will learn how to use JavaWeb technology to develop a shopping mall for selling local products, and master the related design and implementation methods.

2. Development technology

2.1 JSP technology

JSP (JavaServer Pages) is a dynamic web development technology closely related to Servlet. JSP enables developers to embed Java code into HTML pages to generate dynamic content.

JSP uses JSP tags to control the logical processing and display of the page. These tags allow developers to embed Java code, JSTL tag libraries, or custom tags.

When JSPs are requested by the server, they are first translated into Servlets, and then the Servlet container is responsible for running the Servlets. Therefore, JSP operates very similarly to Servlet.

Advantages of JSP include:

  • Simplified the development of Web applications: JSP allows developers to embed Java code into HTML pages, which greatly simplifies the development process of Web applications.
  • Code can be reused: JSP can call Java Bean components, custom tags and other Java classes, so that existing Java code can be reused.
  • Better readability: JSP codes are easier to read and maintain than traditional Servlets because they reduce the mixing between Java code and HTML markup.

However, JSP also has some disadvantages. For example, when JSP becomes complex, it is difficult to maintain; there may also be security issues, requiring strict input validation and filtering to prevent cross-site scripting attacks and other issues.

2.2 Servlet

Servlet is a Java technology that allows developers to write dynamic web applications. Servlets are mainly used to process HTTP requests and responses to generate dynamic content.

Servlets are run by Servlet containers such as Tomcat or Jetty. When a client (usually a Web browser) sends a request to the server, the Servlet container will call the corresponding Servlet to process the request. Servlets can read request data, perform logical processing, and output response data.

Similar to JSP, Servlet can be written in Java language. But unlike JSP, Servlet has no HTML code at all, but is completely composed of Java code. Therefore, Servlets are generally more flexible and efficient than JSPs.

The advantages of Servlets include:

  • Can generate dynamic content: Servlet can dynamically generate page content according to request parameters, session status, etc. This allows developers to create more flexible web applications.
  • No specific templating language: Since a Servlet is entirely composed of Java code, it does not use any specific templating language. This means developers can use whatever Java libraries and frameworks they like.
  • More maintainable: Servlet code is generally more maintainable than JSP code because they are easier to read and test, and since there is no HTML code, they are less confusing.

However, Servlets also have some disadvantages. For example, developing Servlets may require more Java programming knowledge; they may require more networking and Web programming knowledge than JSP. Also, because Servlets don't have a built-in templating language, generating HTML code can be more complicated.

2.3 Mysql database

MySQL is an open source relational database management system (RDBMS), which is developed and maintained by the Swedish MySQL AB company. MySQL is widely used in web development because of its ease of use, scalability, support for multiple platforms, and high performance.

Features of MySQL include:

  • Open Source: MySQL is an open source software and is available under the GNU General Public License (GPL) or a commercial license.
  • Scalability: MySQL can be easily expanded to any size, and the processing power of a single server can be increased by adding more servers to achieve horizontal expansion or vertical expansion.
  • High performance: MySQL is a high-performance relational database that can quickly process large amounts of data and complex queries.
  • Security: MySQL provides secure authentication and authorization functions to ensure that only authorized users can access sensitive data.
  • Multi-platform support: MySQL can run on multiple operating systems such as Windows, Linux, and UNIX.

In addition to the above features, MySQL also has the following important aspects:

  • Database type: MySQL supports many different data types, including integers, floating point numbers, strings, dates and times, and more.
  • SQL Support: MySQL supports SQL (Structured Query Language), a widely used standard query language for managing and querying data in relational databases.
  • Storage engine: MySQL supports multiple storage engines, including InnoDB, MyISAM, etc. Each engine has different advantages and scope of application.
  • Extensibility: MySQL can extend its functionality by adding plugins or custom functions.

In summary, MySQL is a reliable, high-performance, easy-to-use, multi-platform supported relational database management system for a wide range of web applications and enterprise applications.

2.4 JDBC

JDBC (Java Database Connectivity) is an API for communication between Java applications and databases. It provides a standardized way to connect to different types of databases and use SQL statements to query and update data.

The main advantages of J DBC include:

  • Portability: The JDBC API defines a set of standard interfaces that enable communication with multiple database management systems (DBMS). Since the JDBC API is standardized, applications can be easily converted from one DBMS to another.
  • Security: JDBC provides a variety of security mechanisms, such as encrypted transmission, authentication and authorization, etc., to protect sensitive data from unauthorized access.
  • Ease of use: JDBC API is easy to understand and use. Developers can perform various database operations through simple API calls, such as query, insert, update, and delete.
  • High Performance: The JDBC API has good performance and excels when dealing with large amounts of data.

Basically, the JDBC API defines a set of Java classes and interfaces that provide a standard way to connect to a database, send SQL statements, and process result sets. The JDBC API also provides support for functions such as connection pooling, transactions, batch processing, and metadata.

Although JDBC is a powerful and flexible API, using JDBC still requires some knowledge of Java programming. Many Java frameworks and development tools (such as Spring, Hibernate, etc.) provide a higher level of abstraction to simplify JDBC programming. These frameworks and tools make interacting with databases easier while providing additional functionality and convenience.

3. Functional design

The system is divided into two parts: foreground users and background administrators.

Foreground user functions:

(1) User login

(2) User registration

(3) The user views the product

(4) Users search for products

(5) Add the product to the shopping cart

(6) Commodity settlement and payment confirmation

(7) I want to leave a message and give feedback to view

(8) Comment on the product

(9) Review and modify personal information

(10) View order information

(11) View news information

Background administrator functions:

(1) login

(2) Password modification

(3) News and information management

(4) Commodity classification management

(5) Commodity information management

(6) Order information management

(7) Registered user information management

(8) Comment and message management

(9) Message feedback management

(10) Data statistics management

4. Functional renderings

4.1 Client

4.1.1 Home page

The home page includes the navigation bar, local product information and its tail composition. The overall design is mainly green, and the specialty that highlights the whole is the theme of pure nature and pollution-free.

 4.1.2 Commodity information

Commodity information is to display all the special product information of the mall. You can check how many pieces of information there are in total, switch between the previous page and the next page, and click to view the detailed information of each product.

 

 4.1.3 Hot Recommendations

 The background of the hot-selling recommendation display wants to focus on products that are of interest to customers, help buyers view and filter, quickly locate the hot-selling products on the platform, and facilitate purchases.

 4.1.4 All categories

All categories are used to provide the entrance to filter products by category. Clicking all will display all special product information. If you want to accurately find the special product information of a certain category, you can click on the corresponding product, and the list can filter out the desired list information.

 4.1.5 Commodity query

Commodity query quickly helps customers filter products according to price, classification, name and other conditions. After inputting, click Submit immediately to display the product information you want to search.

 4.1.6 News information

News information is to display various precautions and information that you want to present to customers, so that customers can better understand and trust the platform.

  4.1.7 Shopping Cart and Order

The shopping cart is the core function of the platform. The purpose of customers to view and filter products is to purchase, but for the convenience of ordering and screening, they will put all interested ones in the shopping cart first, and then place an order and pay in a unified manner. When purchasing additional products, the user must be logged in.

Enter your name, address, and phone number to submit and generate an order, and complete the payment. (A simulated payment is used here)

 

4.1.8 I want to leave a message

I want to leave a message is for users to leave a message on the platform and ask what they want to know. After the background administrator replies to the message, the feedback content can also be seen.

4.1.9 Member Center

In the member center, you can view personal information, change passwords, view orders and view message operations.

4.2 Background administrator side

4.2.1 Home page

After successful login, the user enters the home page of the background management terminal, which is divided into the left menu bar, the top information bar and its main content. On the home page, you will be prompted with the delivery order information.

 4.2.2 Commodity information management

Commodity information management mainly includes adding categories, viewing categories, modifying and deleting categories, adding commodity information, viewing commodity information, modifying and deleting commodity information.

4.2.3 Registered user management

 Registered user management includes user information viewing and user information viewing.

 4.2.4 Order information management

Order information management includes order information management and viewing order information. It is mainly able to perform operations such as viewing, shipping, and deleting.

5. Core code

public class AdminServlet extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public AdminServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request,response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType(Constant.CONTENTTYPE);
		request.setCharacterEncoding(Constant.CHARACTERENCODING);
		String date=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime());
		String date2=new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());
		try{
			String method=request.getParameter("method").trim();
			ComBean cBean = new ComBean();
			HttpSession session = request.getSession();   
			if(method.equals("one")){//用户登录
				String username = request.getParameter("username");
				String password = request.getParameter("password");  
					String str=cBean.getString("select realname from admin where username='"+username+"' and  password='"+password+"'  ");
					if(str==null){
						request.setAttribute("message", "登录信息错误!");
						request.getRequestDispatcher("admin/login.jsp").forward(request, response); 
					}
					else{
						session.setAttribute("user", username);  
						request.getRequestDispatcher("admin/index.jsp").forward(request, response); 
					}  
			}
			else if(method.equals("uppwd")){//修改密码
				String username=(String)session.getAttribute("user"); 
				String oldpwd = request.getParameter("oldpwd"); 
				String newpwd = request.getParameter("newpwd"); 
				String str=cBean.getString("select id from admin where username='"+username+"' and  password='"+oldpwd+"'");
				if(str==null){
					request.setAttribute("message", "原始密码信息错误!");
					request.getRequestDispatcher("admin/system/editpwd.jsp").forward(request, response); 
				}
				else{
					int flag=cBean.comUp("update admin set password='"+newpwd+"' where username='"+username+"'");
					if(flag == Constant.SUCCESS){ 
						request.setAttribute("message", "操作成功!");
						request.getRequestDispatcher("admin/system/editpwd.jsp").forward(request, response); 
					}
					else { 
						request.setAttribute("message", "操作失败!");
						request.getRequestDispatcher("admin/system/editpwd.jsp").forward(request, response); 
					}
				}
			}
			else if(method.equals("adminexit")){//退出登录
				session.removeAttribute("user");  session.removeAttribute("sf");  
				request.getRequestDispatcher("index.jsp").forward(request, response); 
			}
			else if(method.equals("addm")){//增加系统用户
				String username = request.getParameter("username"); 
				String password = request.getParameter("password"); 
				String realname = request.getParameter("realname"); 
				String sex = request.getParameter("sex"); 
				String age = request.getParameter("age"); 
				String address = request.getParameter("address"); 
				String tel = request.getParameter("tel");
				String str=cBean.getString("select id from admin where username='"+username+"'");
				if(str==null){ 
						int flag=cBean.comUp("insert into admin(username,password,realname,sex,age,address,tel,addtime) " +
								"values('"+username+"','"+password+"','"+realname+"','"+sex+"','"+age+"','"+address+"','"+tel+"','"+date2+"')");
						if(flag == Constant.SUCCESS){ 
							request.setAttribute("message", "操作成功!");
							request.getRequestDispatcher("admin/system/index.jsp").forward(request, response); 
						}
						else { 
							request.setAttribute("message", "操作失败!");
							request.getRequestDispatcher("admin/system/index.jsp").forward(request, response); 
						} 
				}
				else{
					request.setAttribute("message", "该用户名已存在!");
					request.getRequestDispatcher("admin/system/index.jsp").forward(request, response); 
				} 
			}
			else if(method.equals("upm")){//修改系统用户
				String id = request.getParameter("id");
				String password = request.getParameter("password");
				String realname = request.getParameter("realname"); 
				String sex = request.getParameter("sex"); 
				String age = request.getParameter("age"); 
				String address = request.getParameter("address"); 
				String tel = request.getParameter("tel"); 
				int flag=cBean.comUp("update admin set password='"+password+"',realname='"+realname+"',sex='"+sex+"',age='"+age+"'," +
						"address='"+address+"',tel='"+tel+"' where id='"+id+"'");
				if(flag == Constant.SUCCESS){ 
					request.setAttribute("message", "操作成功!");
					request.getRequestDispatcher("admin/system/index.jsp").forward(request, response); 
				}
				else { 
					request.setAttribute("message", "操作失败!");
					request.getRequestDispatcher("admin/system/index.jsp").forward(request, response); 
				}
			}
			else if(method.equals("delm")){//删除系统用户
				String id = request.getParameter("id");  
				int flag=cBean.comUp("delete from admin where id='"+id+"'");
				if(flag == Constant.SUCCESS){ 
					request.setAttribute("message", "操作成功!");
					request.getRequestDispatcher("admin/system/index.jsp").forward(request, response); 
				}
				else { 
					request.setAttribute("message", "操作失败!");
					request.getRequestDispatcher("admin/system/index.jsp").forward(request, response); 
				}
			} 
			else if(method.equals("upm2")){//修改系统用户
				String username=(String)session.getAttribute("user");
				String realname = request.getParameter("realname"); 
				String sex = request.getParameter("sex"); 
				String age = request.getParameter("age"); 
				String address = request.getParameter("address"); 
				String tel = request.getParameter("tel"); 
				int flag=cBean.comUp("update admin set realname='"+realname+"',sex='"+sex+"',age='"+age+"'," +
						"address='"+address+"',tel='"+tel+"' where username='"+username+"'");
				if(flag == Constant.SUCCESS){ 
					request.setAttribute("message", "操作成功!");
					request.getRequestDispatcher("admin/system/index2.jsp").forward(request, response); 
				}
				else { 
					request.setAttribute("message", "操作失败!");
					request.getRequestDispatcher("admin/system/index2.jsp").forward(request, response); 
				}
			}
			else{//无参数传入转到错误页面
				request.getRequestDispatcher("error.jsp").forward(request, response);
			}
		}catch(Exception e){
			e.printStackTrace();
			request.getRequestDispatcher("error.jsp").forward(request, response);
		}
		
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occure
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
public class MemberServlet extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public MemberServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request,response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType(Constant.CONTENTTYPE);
		request.setCharacterEncoding(Constant.CHARACTERENCODING);
		HttpSession session = request.getSession();
		ComBean cBean = new ComBean();
		String date=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime());
		String date2=new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());
		String method = request.getParameter("method");
		if(method.equals("mreg")){ //用户注册
			String username = request.getParameter("username"); 
			String password = request.getParameter("password"); 
			String realname = request.getParameter("realname"); 
			String sex = request.getParameter("sex"); 
			String age = request.getParameter("age"); 
			String tel = request.getParameter("tel"); 
			String email = request.getParameter("email");
			
			if(username.equals("admin")){
				request.setAttribute("message", "非法的用户名!");
				request.getRequestDispatcher("reg.jsp").forward(request, response); 
			}
			else{
				String str=cBean.getString("select id from member where username='"+username+"'");
				if(str==null){
					int flag=cBean.comUp("insert into member(username,password,realname,sex,age,tel,email,regtime) " +
							"values('"+username+"','"+password+"','"+realname+"','"+sex+"','"+age+"','"+tel+"','"+email+"','"+date2+"')");
					if(flag == Constant.SUCCESS){ 
						request.setAttribute("message", "注册成功请登录!");
						request.getRequestDispatcher("login.jsp").forward(request, response); 
					}
					else { 
						request.setAttribute("message", "操作失败!");
						request.getRequestDispatcher("reg.jsp").forward(request, response); 
					}
				}
				else{
					request.setAttribute("message", "该用户名已存在!");
					request.getRequestDispatcher("reg.jsp").forward(request, response); 
				} 
			}
			
		}
		else if(method.equals("mupreg")){ //用户修改注册资料
			String member=(String)session.getAttribute("member"); 
			String realname = request.getParameter("realname"); 
			String sex = request.getParameter("sex"); 
			String age = request.getParameter("age"); 
			String tel = request.getParameter("tel"); 
			String email = request.getParameter("email"); 
			int flag=cBean.comUp("update member set realname='"+realname+"',sex='"+sex+"',age='"+age+"'," +
					"tel='"+tel+"',email='"+email+"' where username='"+member+"'");
			if(flag == Constant.SUCCESS){ 
				request.setAttribute("message", "操作成功!");
				request.getRequestDispatcher("member/info/index.jsp").forward(request, response); 
			}
			else { 
				request.setAttribute("message", "操作失败!");
				request.getRequestDispatcher("member/info/index.jsp").forward(request, response); 
			}
		}
		else if(method.equals("mlogin")){//用户登录 代码都有注释的哦 
			String username = request.getParameter("username"); 
			String password = request.getParameter("password");   
				String str=cBean.getString("select id from member where username='"+username+"' and  password='"+password+"' and ifuse='在用'");
				if(str==null){
					request.setAttribute("message", "登录信息错误!");
					request.getRequestDispatcher("login.jsp").forward(request, response); 
				}
				else{
					session.setAttribute("member", username); 
					request.getRequestDispatcher("member/index.jsp").forward(request, response); 
				} 
		}
		else if(method.equals("lost")){ //丢失密码
			String username = request.getParameter("username"); 
			String str=cBean.getString("select id from member where username='"+username+"' and ifuse='在用'");
			if(str==null){
				request.setAttribute("message", "无此用户或已经被管理员停用!");
				request.getRequestDispatcher("login.jsp").forward(request, response); 
			}
			else{
				cBean.comUp("update member set password='111' where username='"+username+"'");
				request.setAttribute("message", "新密码为111,请登录后修改!");
				request.getRequestDispatcher("index.jsp").forward(request, response);
			}  
		}
		else if(method.equals("memberexit")){ //退出登录
			session.removeAttribute("member");
			request.getRequestDispatcher("index.jsp").forward(request, response);
		}
		else if(method.equals("muppwd")){//用户修改密码
			String member=(String)session.getAttribute("member"); 
			String oldpwd = request.getParameter("oldpwd"); 
			String newpwd = request.getParameter("newpwd"); 
			String str=cBean.getString("select id from member where username='"+member+"' and  password='"+oldpwd+"'");
			if(str==null){
				request.setAttribute("message", "原始密码信息错误!");
				request.getRequestDispatcher("member/info/editpwd.jsp").forward(request, response); 
			}
			else{
				int flag=cBean.comUp("update member set password='"+newpwd+"' where username='"+member+"'");
				if(flag == Constant.SUCCESS){ 
					request.setAttribute("message", "操作成功!");
					request.getRequestDispatcher("member/info/editpwd.jsp").forward(request, response); 
				}
				else { 
					request.setAttribute("message", "操作失败!");
					request.getRequestDispatcher("member/info/editpwd.jsp").forward(request, response); 
				}
			}
		}
		/管理员操作
		else if(method.equals("delm")){//删除用户
			String id = request.getParameter("id");  
			int flag=cBean.comUp("delete from member where id='"+id+"'");
			if(flag == Constant.SUCCESS){
				request.setAttribute("message", "操作成功!");
				request.getRequestDispatcher("admin/member/index.jsp").forward(request, response); 
			}
			else{
				request.setAttribute("message", "操作失败!");
				request.getRequestDispatcher("admin/member/index.jsp").forward(request, response); 
			}
		}
		else if(method.equals("ifusem")){//停用/在用 用户
			String id = request.getParameter("id");  
			String sql="";
			String str=cBean.getString("select ifuse from member where id='"+id+"'");
			if(str.equals("在用")){
				sql="update member set ifuse='停用' where id='"+id+"'";
			}
			else{
				sql="update member set ifuse='在用' where id='"+id+"'";
			}
			int flag=cBean.comUp(sql);
			if(flag == Constant.SUCCESS){
				request.setAttribute("message", "操作成功!");
				request.getRequestDispatcher("admin/member/index.jsp").forward(request, response); 
			}
			else{
				request.setAttribute("message", "操作失败!");
				request.getRequestDispatcher("admin/member/index.jsp").forward(request, response); 
			}
		}
		
		 
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occure
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
public final class Common {
	字符串 HTML 转换
	public static String turn(String str) {
	
		while (str.indexOf("\n") != -1) {
			str = str.substring(0, str.indexOf("\n")) + "<br>"
					+ str.substring(str.indexOf("\n") + 1);
		}
		while (str.indexOf(" ") != -1) {
			str = str.substring(0, str.indexOf(" ")) + "&nbsp;"
					+ str.substring(str.indexOf(" ") + 1);
		}
		return str;
	}
	
	/返回日期  当前日期传入0  一年之前传入-1 三年后传入3
	public static String getDate(int num){
	
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		Calendar c = Calendar.getInstance();
		c.add(Calendar.YEAR, num);
		
		return df.format(c.getTime());
	}
	
	/数据库输出字符串的过滤
	public static String SQLStr(String str){
	
		if(str != null && str.length()>1 && str.substring(0,1).equals("?")){
			str = str.substring(1);
		}
				
		if(str == null || str.equals("") || str.equals(" ")){
			str = "&nbsp;";
		}
		return str;
	} 
	/过滤空格
	public static String PageStr(String str){
	
		if(str==null || str.trim().equals("") || str.equals(" ")||str.equals("null")){
			str = "";
		}
		str = str.trim();
		return str;
	}
	/格式化日期	
	public static String formatRZ(String oldDate){
	
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		Date Date = new Date(oldDate);
		return df.format(Date);
	}
	
	汉化
	public static String toChineseAndTrim(String str){
	
		if(str==null){
			str="";
		}
		try{
			byte b[]=str.getBytes("iso-8859-1");
			str=new String(b);
			str=str.trim();
		}catch(Exception e){
			e.printStackTrace();
		}
		return str;
	}
}
public class DBO {

	private Connection conn;
	private Statement stmt;
  	private DataSource ds;
	
	public DBO()
	{
	}

	/**
		打开数据库
	*/
	public void open() 
	{
		try 
		{
			Class.forName("com.mysql.jdbc.Driver"); 
			conn=DriverManager.getConnection("jdbc:mysql://localhost/dg?useUnicode=true&characterEncoding=utf-8","root","root"); 
			stmt=conn.createStatement();
		} 
		catch (Exception ex) 
		{
		System.err.println("打开数据库时出错: " + ex.getMessage());
		}
	}

	/**
		关闭数据库,将连接返还给连接池
	*/
	public void close() 
	{
		try 
		{
		
				
		//	connMgr.freeConnection("java", conn);
			conn.close();
		} 
		catch (SQLException ex) 
		{
			System.err.println("返还连接池出错: " + ex.getMessage());
		}
	}

	/**
		执行查询
	*/
	public ResultSet executeQuery(String sql) throws SQLException
	{
		ResultSet rs = null;
		

		rs = stmt.executeQuery(sql);
		return rs;
	}

	/**
		执行增删改
	*/
	public int executeUpdate(String sql) throws SQLException
	{
		int ret = 0;
		
	
		ret = stmt.executeUpdate(sql);
	
		return ret;
	}

	/**
		将SQL语句加入到批处理
	*/
	public void addBatch(String sql) throws SQLException 
	{
		stmt.addBatch(sql);
	}

	/**
		执行批处理
	*/
	public int [] executeBatch() throws SQLException 
	{
		boolean isAuto=conn.getAutoCommit();
		
		conn.setAutoCommit(false);
		int [] updateCounts = stmt.executeBatch();
		
//		conn.commit();
		
//		conn.setAutoCommit(isAuto);
		//conn.setAutoCommit(true);
		return updateCounts;
	}
	public boolean getAutoCommit() throws SQLException
	{
		return conn.getAutoCommit();
	}
	public void setAutoCommit(boolean auto)  throws SQLException 
	{
		conn.setAutoCommit(auto);
	}
	
	public void commit() throws SQLException 
	{
		conn.commit();
//		this.close();
	}
	public void rollBack() throws SQLException 
	{
		conn.rollback();
//		this.close();
	}
	
}

7. Summary

This project is based on JavaWeb technology, adopts MVC structure mode, uses JSP, Servlet and other technologies, and realizes page layout through front-end technologies such as html and css. Implemented the following functions:

(1) User registration, login and member center management.

(2) Commodity classification and commodity search function.

(3) The function of adding goods to the shopping cart and placing an order.

(4) Users can view orders, confirm receipt, delete orders and other functions.

(5) Users can browse and comment on products posted by other users.

(6) The platform administrator can publish and delete products, manage user information and order information, etc.

During the development of the project, the following problems were encountered:

(1) Rights management issues: In the project, it is necessary to distinguish rights between users and administrators, and it is necessary to impose corresponding operation restrictions on different rights roles.

(2) Hierarchical structure of product classification: In the design process of product classification, it is necessary to consider that different product classifications have different hierarchical structures, and the classification needs to be processed recursively.

(3) Database design issues: When designing a database, it is necessary to consider data storage and reading efficiency issues, as well as data redundancy issues.

In the process of project realization, through consulting materials, technical learning, and immersing in solving bugs, I have improved my coding convenience to a certain extent, and realized the development and completion of the project to a certain extent.

If you like it, you can like it, collect it, pay attention to it, and communicate with the author in private messages

Guess you like

Origin blog.csdn.net/lf21qp/article/details/131394429