作者主页:夜未央5788
简介:Java领域优质创作者、Java项目、学习资料、技术互助
文末获取源码
基于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.
- */
- 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.
- *
- * @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.
- */
- 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("");
- }
- }
-
- public void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- doGet(request,response);
- }
-
- /**
- * Initialization of the servlet.
- *
- * @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.
- */
- 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("");
- }
- }
-
- public void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- doGet(request,response);
- }
-
- /**
- * Initialization of the servlet.
- *
- * @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.
- */
- 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.
- *
- * @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.
- */
- 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.
- *
- * @throws ServletException if an error occure
- */
- public void init() throws ServletException {
- // Put your code here
- }
-
- }
如果也想学习本系统,下面领取。关注并回复:007jsp