Java项目:基于JSP+Servlet的网上订餐管理系统

作者主页:夜未央5788

 简介:Java领域优质创作者、Java项目、学习资料、技术互助

文末获取源码

基于JSP+Servlet的网上订餐管理系统的设计与实现

项目介绍

基于JSP+Servlet的网上订餐管理系统的设计与实现。该项目为前后台管理项目。前台主要展示给普通用户,主要功能有菜品分类、最新菜品、销售排行、美食预订、营养小贴士、餐点搜索、订餐车、在线留言等;

后台主要提供给管理员,主要功能有菜品管理、菜品类别管理、营养小贴士管理、会员管理、员工管理、留言管理、采购管理、销售订单查询、统计管理、用户管理等;

环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。

2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.是否Maven项目: 否;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目 

6.数据库:MySql 5.7版本;

技术栈

1. 后端:Servlet

2. 前端:JSP+bootstrap+jQuery

使用说明

1. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;

若为maven项目,导入成功后请执行maven clean;maven install命令,下载所需jar包;

2. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
3. 将项目中DBConn.java文件中的数据库配置改为自己的配置
4. 配置tomcat,然后运行项目,输入localhost:8080/xxx 登录
5. 后台管理员账户:admin  密码:admin

前台普通用户:111  密码:111

运行截图

前台界面

 

 

 

 

 

后台界面

 

 

 

 

 

 

 

 

 

相关代码 

AdminLoginBean

package com.itbaizhan.bean;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import com.itbaizhan.util.DBConn;


public class AdminLoginBean {
	
	Connection conn = null;
	Statement st = null;
	ResultSet rs = null;
	ArrayList al = new ArrayList();
	
	public int login(String name,String pwd){
		int temp = 0;
		conn = DBConn.getConn();
		try {
			st = conn.createStatement();
			rs = st.executeQuery("select * from admin where name='"+name+"'");
			if(rs.next()){
				String id = rs.getString("id");
				String tname = rs.getString("name");
				String tpwd = rs.getString("pwd");			
				if(pwd.equals(tpwd)){
					temp = 1;
					al.add(id);
					al.add(tname);
					al.add(tpwd);
				}else{
					temp = 2;
				}
			}else{
				temp = 3;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally{
			DBConn.close(conn,st,rs);
		}
		return temp;
	}
	
	public ArrayList getArrayLst(){
		return al;
	}

}

ListServlet

package com.itbaizhan.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.itbaizhan.bean.SelectBean;

public class ListServlet extends HttpServlet {

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

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

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		

		SelectBean ib = new SelectBean();
		
		String sql1 = "select * from types";
		String[] args1 = {"id","name"};
		ArrayList al1 = ib.select(sql1, args1);
		request.setAttribute("type", al1);
		
		String sql2 = "select * from books";
		String[] args2 = {"id","name","author","publishing","number","price","storage","brief","type","tate","sums","imgpath","price1","sums1"};
		ArrayList al2 = ib.select(sql2, args2);
		request.setAttribute("books", al2);
		
		String sql3 = "select * from books order by sums1 desc";
		String[] args3 = {"id","name","author","publishing","number","price","storage","brief","type","tate","sums","imgpath","price1","sums1"};
		ArrayList al3 = ib.select(sql3, args3);
		request.setAttribute("xiaosou", al3);
		
		String sql5 = "select * from books where tate=1";
		String[] args5 = {"id","name","author","publishing","number","price","storage","brief","type","tate","sums","imgpath","price1","sums1"};
		ArrayList al5 = ib.select(sql5, args5);
		request.setAttribute("tuibook", al5);
		
		String sql6 = "select * from books where tate=2";
		String[] args6 = {"id","name","author","publishing","number","price","storage","brief","type","tate","sums","imgpath","price1","sums1"};
		ArrayList al6 = ib.select(sql6, args6);
		request.setAttribute("newbook", al6);
		
		String sql7 = "select * from users";
		String[] args7 = {"id","name","pwd","realname","sex","age","card","address","phone","email","code"};
		ArrayList al7 = ib.select(sql7, args7);
		request.setAttribute("users", al7);
		
		String sql10 = "select * from leaveword";
		String[] args10 = {"id","users","title","content","times"};
		ArrayList al10 = ib.select(sql10, args10);
		request.setAttribute("leaveword", al10);
		
		String sql13 = "select * from books order by id desc";
		String[] args13 = {"id","name","author","publishing","number","price","storage","brief","type","tate","sums","imgpath","price1","sums1"};
		ArrayList al13 = ib.select(sql13, args13);
		request.setAttribute("xiaosou1", al13);
		
		String sql14 = "select * from nutrition";
		String[] args14 = {"id","name","content"};
		ArrayList al14 = ib.select(sql14, args14);
		request.setAttribute("nutrition", al14);
		
		String sql15 = "select * from emp";
		String[] args15 = {"id","name","sex","birthday","phone","addr","duty","estate"};
		ArrayList al15 = ib.select(sql15, args15);
		request.setAttribute("emp", al15);
		
		String sql16 = "select * from stock";
		String[] args16 = {"id","name","unit","sums","price","times"};
		ArrayList al16 = ib.select(sql16, args16);
		request.setAttribute("stock", al16);
		
		
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request,response);
	}

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

}

SessAdminServlet

package com.itbaizhan.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SessAdminServlet extends HttpServlet {

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

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

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		PrintWriter pw = response.getWriter();
		if(request.getSession().getAttribute("adminlogin") == null || request.getSession().getAttribute("adminlogin").equals("")){
			pw.write("<script>alert('Äú»¹Ã»ÓеǼ!');window.navigate('index.jsp');</script>");
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request,response);
	}

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

}

SessLoginServlet

package com.itbaizhan.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SessLoginServlet extends HttpServlet {

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

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

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		PrintWriter pw = response.getWriter();
		if(request.getSession().getAttribute("login") == null || request.getSession().getAttribute("login").equals("")){
			pw.write("<script>alert('Please login!');window.navigate('../qiantai/index.jsp');</script>");
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request,response);
	}

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

}

BeforehandBookServlet

package com.itbaizhan.servlet.qiantai;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.itbaizhan.bean.InsertUpdateDelBean;
import com.itbaizhan.util.Validate;



public class BeforehandBookServlet extends HttpServlet {

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

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

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		Validate vd = new Validate();
		String bookid = vd.getUnicode(request.getParameter("bookid"));
		String price = vd.getUnicode(request.getParameter("price"));
		HttpSession session = request.getSession();
		ArrayList login = (ArrayList)session.getAttribute("login");
		InsertUpdateDelBean ib = new InsertUpdateDelBean();
		String sql = "insert into beforehand(users,books,price) values('"+login.get(0)+"','"+bookid+"','"+price+"')";
		ib.insertANDupdateANDdel(sql);
		request.setAttribute("okbeforehand", "1");
		RequestDispatcher rd=request.getRequestDispatcher("/qiantai/loan_book_note.jsp");
        rd.forward(request,response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

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

}

BookinfServlet

package com.itbaizhan.servlet.qiantai;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.itbaizhan.bean.SelectBean;
import com.itbaizhan.util.Validate;



public class BookinfServlet extends HttpServlet {

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

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

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		SelectBean ib = new SelectBean();
		Validate vd = new Validate();
		String id = vd.getUnicode(request.getParameter("id"));
		String adminshow = vd.getUnicode(request.getParameter("adminshow"));
		String adminupdate = vd.getUnicode(request.getParameter("adminupdate"));
		String str = "/qiantai/bookinf.jsp";
		String sql2 = "select * from books where id="+id;
		String[] args2 = {"id","name","author","publishing","number","price","storage","brief","type","tate","sums","imgpath","price1","sums1"};
		ArrayList al2 = ib.select(sql2, args2);
		request.setAttribute("bookinf", al2);
		if(adminshow != null && !adminshow.equals("")){
			str ="/admin/showbook.jsp";
		}
		if(adminupdate != null && !adminupdate.equals("")){
			str ="/admin/updatebook.jsp";
		}
		RequestDispatcher rd=request.getRequestDispatcher(str);
        rd.forward(request,response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request,response);
	}

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

}

如果也想学习本系统,下面领取。关注并回复:007jsp

  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

夜未央5788

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值