• 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

    1. package com.itbaizhan.bean;
    2. import java.sql.Connection;
    3. import java.sql.ResultSet;
    4. import java.sql.SQLException;
    5. import java.sql.Statement;
    6. import java.util.ArrayList;
    7. import com.itbaizhan.util.DBConn;
    8. public class AdminLoginBean {
    9. Connection conn = null;
    10. Statement st = null;
    11. ResultSet rs = null;
    12. ArrayList al = new ArrayList();
    13. public int login(String name,String pwd){
    14. int temp = 0;
    15. conn = DBConn.getConn();
    16. try {
    17. st = conn.createStatement();
    18. rs = st.executeQuery("select * from admin where name='"+name+"'");
    19. if(rs.next()){
    20. String id = rs.getString("id");
    21. String tname = rs.getString("name");
    22. String tpwd = rs.getString("pwd");
    23. if(pwd.equals(tpwd)){
    24. temp = 1;
    25. al.add(id);
    26. al.add(tname);
    27. al.add(tpwd);
    28. }else{
    29. temp = 2;
    30. }
    31. }else{
    32. temp = 3;
    33. }
    34. } catch (SQLException e) {
    35. e.printStackTrace();
    36. } finally{
    37. DBConn.close(conn,st,rs);
    38. }
    39. return temp;
    40. }
    41. public ArrayList getArrayLst(){
    42. return al;
    43. }
    44. }

    ListServlet

    1. package com.itbaizhan.servlet;
    2. import java.io.IOException;
    3. import java.io.PrintWriter;
    4. import java.util.ArrayList;
    5. import javax.servlet.ServletException;
    6. import javax.servlet.http.HttpServlet;
    7. import javax.servlet.http.HttpServletRequest;
    8. import javax.servlet.http.HttpServletResponse;
    9. import com.itbaizhan.bean.SelectBean;
    10. public class ListServlet extends HttpServlet {
    11. /**
    12. * Constructor of the object.
    13. */
    14. public ListServlet() {
    15. super();
    16. }
    17. /**
    18. * Destruction of the servlet.
    19. */
    20. public void destroy() {
    21. super.destroy(); // Just puts "destroy" string in log
    22. // Put your code here
    23. }
    24. public void doGet(HttpServletRequest request, HttpServletResponse response)
    25. throws ServletException, IOException {
    26. SelectBean ib = new SelectBean();
    27. String sql1 = "select * from types";
    28. String[] args1 = {"id","name"};
    29. ArrayList al1 = ib.select(sql1, args1);
    30. request.setAttribute("type", al1);
    31. String sql2 = "select * from books";
    32. String[] args2 = {"id","name","author","publishing","number","price","storage","brief","type","tate","sums","imgpath","price1","sums1"};
    33. ArrayList al2 = ib.select(sql2, args2);
    34. request.setAttribute("books", al2);
    35. String sql3 = "select * from books order by sums1 desc";
    36. String[] args3 = {"id","name","author","publishing","number","price","storage","brief","type","tate","sums","imgpath","price1","sums1"};
    37. ArrayList al3 = ib.select(sql3, args3);
    38. request.setAttribute("xiaosou", al3);
    39. String sql5 = "select * from books where tate=1";
    40. String[] args5 = {"id","name","author","publishing","number","price","storage","brief","type","tate","sums","imgpath","price1","sums1"};
    41. ArrayList al5 = ib.select(sql5, args5);
    42. request.setAttribute("tuibook", al5);
    43. String sql6 = "select * from books where tate=2";
    44. String[] args6 = {"id","name","author","publishing","number","price","storage","brief","type","tate","sums","imgpath","price1","sums1"};
    45. ArrayList al6 = ib.select(sql6, args6);
    46. request.setAttribute("newbook", al6);
    47. String sql7 = "select * from users";
    48. String[] args7 = {"id","name","pwd","realname","sex","age","card","address","phone","email","code"};
    49. ArrayList al7 = ib.select(sql7, args7);
    50. request.setAttribute("users", al7);
    51. String sql10 = "select * from leaveword";
    52. String[] args10 = {"id","users","title","content","times"};
    53. ArrayList al10 = ib.select(sql10, args10);
    54. request.setAttribute("leaveword", al10);
    55. String sql13 = "select * from books order by id desc";
    56. String[] args13 = {"id","name","author","publishing","number","price","storage","brief","type","tate","sums","imgpath","price1","sums1"};
    57. ArrayList al13 = ib.select(sql13, args13);
    58. request.setAttribute("xiaosou1", al13);
    59. String sql14 = "select * from nutrition";
    60. String[] args14 = {"id","name","content"};
    61. ArrayList al14 = ib.select(sql14, args14);
    62. request.setAttribute("nutrition", al14);
    63. String sql15 = "select * from emp";
    64. String[] args15 = {"id","name","sex","birthday","phone","addr","duty","estate"};
    65. ArrayList al15 = ib.select(sql15, args15);
    66. request.setAttribute("emp", al15);
    67. String sql16 = "select * from stock";
    68. String[] args16 = {"id","name","unit","sums","price","times"};
    69. ArrayList al16 = ib.select(sql16, args16);
    70. request.setAttribute("stock", al16);
    71. }
    72. public void doPost(HttpServletRequest request, HttpServletResponse response)
    73. throws ServletException, IOException {
    74. doGet(request,response);
    75. }
    76. /**
    77. * Initialization of the servlet.
    78. *
    79. * @throws ServletException if an error occure
    80. */
    81. public void init() throws ServletException {
    82. // Put your code here
    83. }
    84. }

    SessAdminServlet

    1. package com.itbaizhan.servlet;
    2. import java.io.IOException;
    3. import java.io.PrintWriter;
    4. import javax.servlet.ServletException;
    5. import javax.servlet.http.HttpServlet;
    6. import javax.servlet.http.HttpServletRequest;
    7. import javax.servlet.http.HttpServletResponse;
    8. public class SessAdminServlet extends HttpServlet {
    9. /**
    10. * Constructor of the object.
    11. */
    12. public SessAdminServlet() {
    13. super();
    14. }
    15. /**
    16. * Destruction of the servlet.
    17. */
    18. public void destroy() {
    19. super.destroy(); // Just puts "destroy" string in log
    20. // Put your code here
    21. }
    22. public void doGet(HttpServletRequest request, HttpServletResponse response)
    23. throws ServletException, IOException {
    24. PrintWriter pw = response.getWriter();
    25. if(request.getSession().getAttribute("adminlogin") == null || request.getSession().getAttribute("adminlogin").equals("")){
    26. pw.write("");
    27. }
    28. }
    29. public void doPost(HttpServletRequest request, HttpServletResponse response)
    30. throws ServletException, IOException {
    31. doGet(request,response);
    32. }
    33. /**
    34. * Initialization of the servlet.
    35. *
    36. * @throws ServletException if an error occure
    37. */
    38. public void init() throws ServletException {
    39. // Put your code here
    40. }
    41. }

    SessLoginServlet

    1. package com.itbaizhan.servlet;
    2. import java.io.IOException;
    3. import java.io.PrintWriter;
    4. import javax.servlet.ServletException;
    5. import javax.servlet.http.HttpServlet;
    6. import javax.servlet.http.HttpServletRequest;
    7. import javax.servlet.http.HttpServletResponse;
    8. public class SessLoginServlet extends HttpServlet {
    9. /**
    10. * Constructor of the object.
    11. */
    12. public SessLoginServlet() {
    13. super();
    14. }
    15. /**
    16. * Destruction of the servlet.
    17. */
    18. public void destroy() {
    19. super.destroy(); // Just puts "destroy" string in log
    20. // Put your code here
    21. }
    22. public void doGet(HttpServletRequest request, HttpServletResponse response)
    23. throws ServletException, IOException {
    24. PrintWriter pw = response.getWriter();
    25. if(request.getSession().getAttribute("login") == null || request.getSession().getAttribute("login").equals("")){
    26. pw.write("");
    27. }
    28. }
    29. public void doPost(HttpServletRequest request, HttpServletResponse response)
    30. throws ServletException, IOException {
    31. doGet(request,response);
    32. }
    33. /**
    34. * Initialization of the servlet.
    35. *
    36. * @throws ServletException if an error occure
    37. */
    38. public void init() throws ServletException {
    39. // Put your code here
    40. }
    41. }

    BeforehandBookServlet

    1. package com.itbaizhan.servlet.qiantai;
    2. import java.io.IOException;
    3. import java.io.PrintWriter;
    4. import java.util.ArrayList;
    5. import javax.servlet.RequestDispatcher;
    6. import javax.servlet.ServletException;
    7. import javax.servlet.http.HttpServlet;
    8. import javax.servlet.http.HttpServletRequest;
    9. import javax.servlet.http.HttpServletResponse;
    10. import javax.servlet.http.HttpSession;
    11. import com.itbaizhan.bean.InsertUpdateDelBean;
    12. import com.itbaizhan.util.Validate;
    13. public class BeforehandBookServlet extends HttpServlet {
    14. /**
    15. * Constructor of the object.
    16. */
    17. public BeforehandBookServlet() {
    18. super();
    19. }
    20. /**
    21. * Destruction of the servlet.
    22. */
    23. public void destroy() {
    24. super.destroy(); // Just puts "destroy" string in log
    25. // Put your code here
    26. }
    27. public void doGet(HttpServletRequest request, HttpServletResponse response)
    28. throws ServletException, IOException {
    29. Validate vd = new Validate();
    30. String bookid = vd.getUnicode(request.getParameter("bookid"));
    31. String price = vd.getUnicode(request.getParameter("price"));
    32. HttpSession session = request.getSession();
    33. ArrayList login = (ArrayList)session.getAttribute("login");
    34. InsertUpdateDelBean ib = new InsertUpdateDelBean();
    35. String sql = "insert into beforehand(users,books,price) values('"+login.get(0)+"','"+bookid+"','"+price+"')";
    36. ib.insertANDupdateANDdel(sql);
    37. request.setAttribute("okbeforehand", "1");
    38. RequestDispatcher rd=request.getRequestDispatcher("/qiantai/loan_book_note.jsp");
    39. rd.forward(request,response);
    40. }
    41. public void doPost(HttpServletRequest request, HttpServletResponse response)
    42. throws ServletException, IOException {
    43. doGet(request, response);
    44. }
    45. /**
    46. * Initialization of the servlet.
    47. *
    48. * @throws ServletException if an error occure
    49. */
    50. public void init() throws ServletException {
    51. // Put your code here
    52. }
    53. }

    BookinfServlet

    1. package com.itbaizhan.servlet.qiantai;
    2. import java.io.IOException;
    3. import java.io.PrintWriter;
    4. import java.util.ArrayList;
    5. import javax.servlet.RequestDispatcher;
    6. import javax.servlet.ServletException;
    7. import javax.servlet.http.HttpServlet;
    8. import javax.servlet.http.HttpServletRequest;
    9. import javax.servlet.http.HttpServletResponse;
    10. import com.itbaizhan.bean.SelectBean;
    11. import com.itbaizhan.util.Validate;
    12. public class BookinfServlet extends HttpServlet {
    13. /**
    14. * Constructor of the object.
    15. */
    16. public BookinfServlet() {
    17. super();
    18. }
    19. /**
    20. * Destruction of the servlet.
    21. */
    22. public void destroy() {
    23. super.destroy(); // Just puts "destroy" string in log
    24. // Put your code here
    25. }
    26. public void doGet(HttpServletRequest request, HttpServletResponse response)
    27. throws ServletException, IOException {
    28. SelectBean ib = new SelectBean();
    29. Validate vd = new Validate();
    30. String id = vd.getUnicode(request.getParameter("id"));
    31. String adminshow = vd.getUnicode(request.getParameter("adminshow"));
    32. String adminupdate = vd.getUnicode(request.getParameter("adminupdate"));
    33. String str = "/qiantai/bookinf.jsp";
    34. String sql2 = "select * from books where id="+id;
    35. String[] args2 = {"id","name","author","publishing","number","price","storage","brief","type","tate","sums","imgpath","price1","sums1"};
    36. ArrayList al2 = ib.select(sql2, args2);
    37. request.setAttribute("bookinf", al2);
    38. if(adminshow != null && !adminshow.equals("")){
    39. str ="/admin/showbook.jsp";
    40. }
    41. if(adminupdate != null && !adminupdate.equals("")){
    42. str ="/admin/updatebook.jsp";
    43. }
    44. RequestDispatcher rd=request.getRequestDispatcher(str);
    45. rd.forward(request,response);
    46. }
    47. public void doPost(HttpServletRequest request, HttpServletResponse response)
    48. throws ServletException, IOException {
    49. doGet(request,response);
    50. }
    51. /**
    52. * Initialization of the servlet.
    53. *
    54. * @throws ServletException if an error occure
    55. */
    56. public void init() throws ServletException {
    57. // Put your code here
    58. }
    59. }

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

  • 相关阅读:
    R语言ggplot2可视化:使用patchwork包将多个ggplot2可视化结果组合起来、两个可视化图像纵向组合之后再和另外一个可视化结果横向组合
    聊聊工作中,如何提升自己的编程能力?
    vscode 远程开发golang
    每个开发人员都应该关注的7个优秀的GitHub仓库
    java计算机毕业设计ssm框架的天气预报系统
    打印机多张双面打印使用说明
    计算机操作系统习题集锦(持续鸽新)
    Verilog:$readmemb和$readmemh系统函数的使用与其中的初始化地址相关问题(详细细节)
    洛谷 P4419 [COCI2017-2018#1] CezarL
    工厂模式之简单工厂模式(常用)
  • 原文地址:https://blog.csdn.net/hanyunlong1989/article/details/127096701