基于javaweb+mysql的jsp+servlet网上订餐管理系统(java+jsp+bootstrap+jquery+mysql)

基于javaweb+mysql的jsp+servlet网上订餐管理系统(java+jsp+bootstrap+jquery+mysql)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

基于javaweb+mysql的JSP+Servlet网上订餐管理系统(java+jsp+bootstrap+jquery+mysql)

项目介绍

基于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
    {
        m_application = pagecontext.getServletContext();
        m_request = (HttpServletRequest)pagecontext.getRequest();
        m_response = (HttpServletResponse)pagecontext.getResponse();
    }

    /**
     * @deprecated Method initialize is deprecated
     */
    public final void initialize(ServletContext servletcontext,HttpSession httpsession,HttpServletRequest httpservletrequest,HttpServletResponse httpservletresponse,JspWriter jspwriter) throws ServletException
    {
        m_application = servletcontext;
        m_request = httpservletrequest;
        m_response = httpservletresponse;
    }

    public void upload() throws ServletException,IOException,SmartUploadException
    {
        int i = 0;
        //boolean flag = false;
        boolean flag1 = false;
        //boolean flag2 = false;
        long l = 0L;
        //String s = "";//new String();
        //String s2 = "";//new String();
        String s4 = ""; //new String();
        String s5 = ""; //new String();
        String s6 = ""; //new String();
        String s7 = ""; //new String();
        String s8 = ""; //new String();
        String s9 = ""; //new String();
        String s10 = ""; //new String();
        m_totalBytes = m_request.getContentLength();
        m_binArray = new byte[m_totalBytes];
        int j;
        for(;i < m_totalBytes;i += j)
        {
            try
            {
                m_request.getInputStream();
                j = m_request.getInputStream().read(m_binArray,i,m_totalBytes - i);
            }
	}

}
package com.demo.servlet.admin;

public class OrderListServlet extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public OrderListServlet() {
		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 username = vd.getUnicode(request.getParameter("username"));
		String bookname = vd.getUnicode(request.getParameter("bookname"));
		String sql = "select a.name as username,realname,b.name as bookname,c.* from users a,books b,loanbook c where a.id=c.users and b.id=c.books ";
		String[] args = {"username","realname","bookname","id","users","books","price","sumday","begintime","endtime","continueday","continuetime","flag"};
		
		if(username != null && !username.equals("")){
			sql += "and a.name like '%"+username+"%'";
		}
		if(bookname != null && !bookname.equals("")){
			sql += "and b.name like '%"+bookname+"%'";
		}
		

        String s = new String(m_binArray,i,(j - i) + 1);
        return s;
    }

    private String getFileName(String s)
    {
        //String s1 = ""; // = new String();
        //String s2 = ""; // = new String();
        //boolean flag = false;
        //boolean flag1 = false;
        //boolean flag2 = false;
        int i = 0;
        i = s.lastIndexOf('/');
        if(i != -1)
        {
            return s.substring(i + 1,s.length());
        }
        i = s.lastIndexOf('\\');
        if(i != -1)
        {
            return s.substring(i + 1,s.length());
        }
        else
        {
            return s;
        }
    }

    public void setDeniedFilesList(String s) throws ServletException,IOException,SQLException
    {
        //String s1 = "";
        if(s != null)
        {
            String s2 = "";
            for(int i = 0;i < s.length();i++)
            {
                if(s.charAt(i) == ',')
                {
                    if(!m_deniedFilesList.contains(s2))
                    {
                        m_deniedFilesList.addElement(s2);
                    }
                    s2 = "";
                }
                else
                {
            }
            InputStream inputstream = resultset.getBinaryStream(s);
            FileOutputStream fileoutputstream = new FileOutputStream(s1);
            int i;
            while((i = inputstream.read()) != -1)
            {
                fileoutputstream.write(i);
            }
            fileoutputstream.close();
        }
        catch(Exception exception)
        {
            throw new SmartUploadException("Unable to save file from the DataBase (1020).");
        }
    }

    private String getDataFieldValue(String s,String s1)
    {
        String s2 = ""; // = new String();
        String s3 = ""; // = new String();
        int i = 0;
        //boolean flag = false;
        //boolean flag1 = false;
        //boolean flag2 = false;
        s2 = s1 + "=" + '"';
        i = s.indexOf(s2);
        if(i > 0)
        {
            int j = i + s2.length();
            int k = j;
            s2 = "\"";
            int l = s.indexOf(s2,j);
            if(k > 0 && l > 0)
            {
                s3 = s.substring(k,l);
            }
        }
        return s3;
    }

    private String getFileExt(String s)
                throw new SmartUploadException("Unable to upload.");
            }
        }

        if(isVirtual(s))
        {
            s = m_application.getRealPath(s);
        }
        try
        {
            java.io.File file = new java.io.File(s);
            FileOutputStream fileoutputstream = new FileOutputStream(file);
            fileoutputstream.write(m_binArray);
            fileoutputstream.close();
        }
        catch(Exception exception1)
        {
            throw new SmartUploadException("The Form cannot be saved in the specified file (1030).");
        }
    }

    private boolean isVirtual(String s)
    {
        if(m_application.getRealPath(s) != null)
        {
            java.io.File file = new java.io.File(m_application.getRealPath(s));
            return file.exists();
        }
        else
        {
            return false;
        }
    }
}
package com.demo.servlet.qiantai;

		String name = vd.getUnicode(request.getParameter("name"));
		String author = vd.getUnicode(request.getParameter("author"));
		String price1 = vd.getUnicode(request.getParameter("price1"));
		String brief = vd.getUnicode(request.getParameter("brief"));
		String type = vd.getUnicode(request.getParameter("type"));
		String sql ="update books set name='"+name+"',author='"+author+"',brief='"+brief+"',type='"+type+"',price1='"+price1+"' where id='"+id+"'";
		InsertUpdateDelBean ib = new InsertUpdateDelBean();
		ib.insertANDupdateANDdel(sql);
		SelectBean sb = new SelectBean();
		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 = sb.select(sql2, args2);
		request.setAttribute("bookinf", al2);
		request.setAttribute("ok", "1");

		RequestDispatcher rd=request.getRequestDispatcher("/admin/updatebook.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
	}

}
package com.demo.servlet.admin;

public class KuXiaoServlet extends HttpServlet {

public class OrderListServlet extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public OrderListServlet() {
		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 username = vd.getUnicode(request.getParameter("username"));
		String bookname = vd.getUnicode(request.getParameter("bookname"));
		String sql = "select a.name as username,realname,b.name as bookname,c.* from users a,books b,loanbook c where a.id=c.users and b.id=c.books ";
		String[] args = {"username","realname","bookname","id","users","books","price","sumday","begintime","endtime","continueday","continuetime","flag"};
		
		if(username != null && !username.equals("")){
			sql += "and a.name like '%"+username+"%'";
		}
		if(bookname != null && !bookname.equals("")){
			sql += "and b.name like '%"+bookname+"%'";
		}
		
		SelectBean sb = new SelectBean();
		ArrayList al = sb.select(sql, args);
		request.setAttribute("order", al);
		RequestDispatcher rd=request.getRequestDispatcher("/admin/order.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 class RegServlet extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public RegServlet() {
		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 name = vd.getUnicode(request.getParameter("name"));
		String pwd = vd.getUnicode(request.getParameter("pwd"));
		String zname = vd.getUnicode(request.getParameter("zname"));
		String sex = vd.getUnicode(request.getParameter("sex"));
		String age = vd.getUnicode(request.getParameter("age"));
		String noid = vd.getUnicode(request.getParameter("noid"));
		String address = vd.getUnicode(request.getParameter("address"));
		String phone = vd.getUnicode(request.getParameter("phone"));
		String email = vd.getUnicode(request.getParameter("email"));
		String code = vd.getUnicode(request.getParameter("code"));
		String sql = "insert into users(name,pwd,realname,sex,age,card,address,phone,email,code) values('"+name+"','"+pwd+"','"+zname+"','"+sex+"','"+age+"','"+noid+"','"+address+"','"+phone+"','"+email+"','"+code+"')";
		InsertUpdateDelBean ib = new InsertUpdateDelBean();
		int flag = ib.insertANDupdateANDdel(sql);
		if(flag == -1){
			request.setAttribute("error", "1");
		}else{
			request.setAttribute("ok", "1");
			response.setHeader("Refresh","5;URL=../qiantai/index.jsp");
		}
		RequestDispatcher rd=request.getRequestDispatcher("/qiantai/reg.jsp");
        rd.forward(request,response);
	}

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


public class ShoppingServlet extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public ShoppingServlet() {
		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 {
		String bookId = request.getParameter("bookId");//获取books_id
		String m = request.getParameter("i"); 
		String num = request.getParameter("num"+m);//获取购物车修改数量
		String str = "";//mapping跳转时的值
		String sql = "select * from books where id="+bookId;//sql语句
		String[] args = {"id","name","author","publishing","number","price","storage","brief","type","tate","sums","imgpath","price1","sums1"};
		String del = request.getParameter("del");//获取删除商品的记号
		String remove = request.getParameter("remove");//获取清空购物车的记号
		HttpSession session = request.getSession();
		ArrayList login = (ArrayList)session.getAttribute("login");//获取用户信息
		SelectBean ib = new SelectBean();
		ArrayList al = ib.select(sql, args);//查询菜品信息
		int sum = 1;//购买一种菜品的数量
		if(login == null || login.size() == 0){
			str = "/servlet/SessLoginServlet";//用户信息不存在跳到首页
		}else{
			str = "/qiantai/shopping.jsp";//跳到购物车页面
			ArrayList shopping = (ArrayList)session.getAttribute("shopping");//获取购物车信息
			if(bookId !=null && !bookId.equals("")){
				ArrayList altem = (ArrayList)al.get(0);
				if(shopping == null || shopping.size() == 0){//购物车为空时
					ArrayList alShop = new ArrayList();
					alShop.add(altem.get(0));
					alShop.add(altem.get(1));
					alShop.add(altem.get(12));
					alShop.add(""+sum);
					shopping = new ArrayList();
					shopping.add(alShop);
				}else{
					boolean bool = true;
					for(int i = 0;i < shopping.size();i++){//查找是否有相同的商品,有的话数目加1
			str = "/admin/nutrition_list.jsp";
			sql = "delete from nutrition where id="+nutrition;
			ib.insertANDupdateANDdel(sql);
		}
		if(emp != null && !emp.equals("")){
			str = "/admin/emp_list.jsp";
			sql = "delete from emp where id="+emp;
			ib.insertANDupdateANDdel(sql);
		}
		if(stock != null && !stock.equals("")){
			str = "/admin/stock_list.jsp";
			sql = "delete from stock where id="+stock;
			ib.insertANDupdateANDdel(sql);
		}
		
		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
	}

}
package com.demo.servlet.admin;

    {
        m_request = httpservletrequest;
        m_response = httpservletresponse;
    }

    public final void initialize(ServletConfig servletconfig,HttpServletRequest httpservletrequest,HttpServletResponse httpservletresponse) throws ServletException
    {
        m_application = servletconfig.getServletContext();
        m_request = httpservletrequest;
        m_response = httpservletresponse;
    }

    public final void initialize(PageContext pagecontext) throws ServletException
    {
        m_application = pagecontext.getServletContext();
        m_request = (HttpServletRequest)pagecontext.getRequest();
        m_response = (HttpServletResponse)pagecontext.getResponse();
    }

    /**
     * @deprecated Method initialize is deprecated
     */
    public final void initialize(ServletContext servletcontext,HttpSession httpsession,HttpServletRequest httpservletrequest,HttpServletResponse httpservletresponse,JspWriter jspwriter) throws ServletException
    {
        m_application = servletcontext;
        m_request = httpservletrequest;
        m_response = httpservletresponse;
    }

    public void upload() throws ServletException,IOException,SmartUploadException
    {
        int i = 0;
        //boolean flag = false;
        boolean flag1 = false;
        //boolean flag2 = false;
        long l = 0L;
        //String s = "";//new String();
        //String s2 = "";//new String();
        String s4 = ""; //new String();
        String s5 = ""; //new String();
        String s6 = ""; //new String();
        String s7 = ""; //new String();
        String s8 = ""; //new String();
            if(m_binArray[i] == (byte)m_boundary.charAt(j))
            {
                if(j == k - 1)
                {
                    m_endData = ((i - k) + 1) - 3;
                    break;
                }
                i++;
                j++;
            }
            else
            {
                i++;
                j = 0;
            }
        }
        m_currentIndex = m_endData + k + 3;
    }

    private String getDataHeader()
    {
        //boolean flag = false;
        int i = m_currentIndex;
        int j = 0;
        for(boolean flag1 = false;!flag1;)
        {
            if(m_binArray[m_currentIndex] == 13 && m_binArray[m_currentIndex + 2] == 13)
            {
                flag1 = true;
                j = m_currentIndex - 1;
                m_currentIndex = m_currentIndex + 2;
            }
            else
            {
                m_currentIndex++;
            }
        }

        String s = new String(m_binArray,i,(j - i) + 1);
        return s;
    }

    private String getFileName(String s)
    {
        //String s1 = ""; // = new String();
        FileNames = new String[m_files.getCount()];
        for(int k = 0;k < m_files.getCount();k++)
        {
            if(!m_files.getFile(k).isMissing())
            {
                //System.out.println("s + m_files.getFile(k).getFileName():" + s + m_files.getFile(k).getFileName());
                m_files.getFile(k).saveAs(s + m_files.getFile(k).getFileName(),i);
                FileNames[j] = s + m_files.getFile(k).getFileName();
                j++;
            }
        }

        return j;
    }

    //Add
    private String[] FileNames;
    public String[] getFileNames()
    {
        //Method may expose internal representation by returning array
        //Returning an array value stored in one of the object's fields exposes the internal representation of the object.? For classes shared by other untrusted classes, this could potentially be a security issue.? Returning a new copy of the array is better approach in many situations.
        String[] vFileNames = new String[FileNames.length];
        System.arraycopy(FileNames,0,vFileNames,0,FileNames.length);
        return vFileNames;
    }

    public int getSize()
    {
        return m_totalBytes;
    }

    public byte getBinaryData(int i)
    {
        byte byte0;
        try
        {
            byte0 = m_binArray[i];
        }
        catch(Exception exception)
        {
            throw new ArrayIndexOutOfBoundsException("Index out of range (1005).");
        }
        return byte0;
    }

    public SmartFiles getFiles()
    {
        return m_files;
    }

            m_response.getOutputStream().write(abyte0,0,j);
        }
        fileinputstream.close();
    }

    public void downloadField(ResultSet resultset,String s,String s1,String s2) throws ServletException,IOException,SQLException
    {
        if(resultset == null)
        {
            throw new IllegalArgumentException("The RecordSet cannot be null (1045).");
        }
        if(s == null)
        {
            throw new IllegalArgumentException("The columnName cannot be null (1050).");
        }
        if(s.length() == 0)
        {
            throw new IllegalArgumentException("The columnName cannot be empty (1055).");
        }
        byte abyte0[] = resultset.getBytes(s);
        if(s1 == null)
        {
            m_response.setContentType("application/x-msdownload");
        }
        else
        {
            if(s1.length() == 0)
            {
                m_response.setContentType("application/x-msdownload");
            }
            else
            {
                m_response.setContentType(s1);
            }
        }
        m_response.setContentLength(abyte0.length);
        if(s2 == null)
        {
            m_response.setHeader("Content-Disposition","attachment;");
        }
        else
        {
            if(s2.length() == 0)
            {
                m_response.setHeader("Content-Disposition","attachment;");
	 * @throws ServletException if an error occure
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
package com.demo.servlet.admin;

public class StatisticServlet extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public StatisticServlet() {
		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 flag = vd.getUnicode(request.getParameter("flag"));
		SelectBean sb = new SelectBean();
		SimpleDateFormat formatter = new SimpleDateFormat ("yyyy-MM-dd kk:mm",Locale.getDefault());
		Date currentDate = new Date();
		String lastdate = formatter.format(currentDate);
		if(flag.equals("1")){
			String sql = "select b.name as bookname,booksum,price1 from books b,orders c where b.id=c.bookid and SUBSTRING(times,1,10)='"+lastdate.substring(0,10)+"'";
			String[] args = {"bookname","booksum","price1"};
		String brief = vd.getUnicode(request.getParameter("brief"));
		String type = vd.getUnicode(request.getParameter("type"));
		String sql ="update books set name='"+name+"',author='"+author+"',brief='"+brief+"',type='"+type+"',price1='"+price1+"' where id='"+id+"'";
		InsertUpdateDelBean ib = new InsertUpdateDelBean();
		ib.insertANDupdateANDdel(sql);
		SelectBean sb = new SelectBean();
		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 = sb.select(sql2, args2);
		request.setAttribute("bookinf", al2);
		request.setAttribute("ok", "1");

		RequestDispatcher rd=request.getRequestDispatcher("/admin/updatebook.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
	}

}
package com.demo.servlet.admin;

public class KuXiaoServlet extends HttpServlet {

	/**
	 * Constructor of the object.
	 */

        PrintWriter out = response.getWriter();
        out.println("<HTML>");
        out.println("<BODY BGCOLOR='white'>");
        out.println("<H1>jspSmartUpload : Servlet Sample</H1>");
        out.println("<HR>");

        // Variables
        int count = 0;
        SmartUpload mySmartUpload = new SmartUpload();

        try
        {
            // Initialization
            mySmartUpload.initialize(config,request,response);

            // Upload
            mySmartUpload.upload();

            // Save the file with the original name
            // in a virtual path of the web server
            count = mySmartUpload.save(mySmartUpload.getRequest().getParameter("PATH"));

            // Display the result
            out.println(count + " file uploaded.");

        }
        catch(Exception e)
        {
            out.println("Unable to upload the file.<br>");
            out.println("Error : " + e.toString());
        }

        out.println("</BODY>");
        out.println("</HTML>");
    }

    /**
     * Destroy the servlet
     */
    public void destroy()
    {
    }

}

请添加图片描述

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值