编程语言
首页 > 编程语言> > JavaWeb版 仿必胜客在线订餐系统

JavaWeb版 仿必胜客在线订餐系统

作者:互联网

一、项目实现成果预览

项目演示

二、项目结构设计

 三、页面设计

(1)注册页面

 (2)主页

(3)会员中心

 个人信息管理页面

用户管理页面

 

(4)地址管理页面

 

 (5)餐品分类管理页面

(6)餐品管理页面 

(7)订单管理页面

 (8)菜单页面

 

(9)购物车页面

 

 四、项目需求文件及源码资源包

项目需求及源码

五、项目代码结构

 

六、控制层及对应前端页面源码

(1)地址管理模块

package com.bsk.controller;


import com.bsk.bean.Address;
import com.bsk.bean.User;
import com.bsk.service.addressService;
import com.bsk.service.impl.addressServiceImpl;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;


@WebServlet("/addressServlet")
public class addressServlet extends BaseServlet {
    private static final long serialVersionUID = 1L;
    private addressService service = new addressServiceImpl();
    //地址列表展示
    public void selectAll(HttpServletRequest request, HttpServletResponse response)throws Exception{
        System.out.println("addressServlet.selectAll");
        // 当前登陆者用户对象
        User user = (User)request.getSession().getAttribute("user");
        String user_id = user.getUserId().toString();
        Address add = new Address();
        List<Address> list = service.selectAllAddress(user_id);
        for (Address address : list) {
            System.out.println(address);
        }

        request.getSession().setAttribute("list",list);
        request.getRequestDispatcher("address.jsp").forward(request,response);

    }

    //新增地址
    public void insertAddress(HttpServletRequest request, HttpServletResponse response)throws Exception{
        System.out.println("addressServlet.insertAddress");
        String Province = request.getParameter("Province");
        String City = request.getParameter("City");
        String District = request.getParameter("District");
        String Describe = request.getParameter("Describe");
        User user = (User)request.getSession().getAttribute("user");
        String userId = user.getUserId().toString();
        System.out.println(Province+"+"+City+"+"+District+"+"+Describe+"+"+userId);

        Address address = new Address();
        address.setAddressProvince(Province);
        address.setAddressCity(City);
        address.setAddressDistrict(District);
        address.setAddressDescribe(Describe);
        address.setUserId(Integer.parseInt(userId));
        System.out.println("address = " + address);

        boolean b = service.insertAddress(address);
        if (b!=true){
            System.out.println("新增地址失败");
            response.getWriter().append("0");
        }else {
            System.out.println("新增地址成功");
            response.getWriter().append("1");
        }
    }

    //删除地址
    public void deletAddress(HttpServletRequest request, HttpServletResponse response)throws Exception{
        System.out.println("addressServlet.deletAddress");
        String id = request.getParameter("id");
        System.out.println(id);
        boolean b = service.deletAddress(id);
        if (b!=true){
            System.out.println("删除地址失败");
            response.getWriter().append("0");
        }else {
            System.out.println("删除地址成功");
            response.getWriter().append("1");
        }
    }

    //修改地址
    public void updateAddress(HttpServletRequest request, HttpServletResponse response)throws Exception{
        System.out.println("addressServlet.updateAddress");
        String id = request.getParameter("addressId");
        String Province = request.getParameter("Province");
        String City = request.getParameter("City");
        String District = request.getParameter("District");
        String Describe = request.getParameter("Describe");
        System.out.println(id+"+"+Province+"+"+City+"+"+District+"+"+Describe);

        boolean b = service.updateAddress(id, Province, City, District, Describe);
        if (b!=true){
            System.out.println("修改地址失败");
            response.getWriter().append("0");
        }else {
            System.out.println("修改地址成功");
            response.getWriter().append("1");
        }
    }
}
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>地址管理</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="css/css.css" />
    <link rel="stylesheet" type="text/css" href="css/style.css" />
    <link rel="stylesheet" type="text/css" href="css/menu.css" />
    <link rel="stylesheet" type="text/css" href="css/address.css" />
    <script type="text/javascript"
            src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="layer/layer.js" type="text/javascript"></script>
    <script src="js/main.js" type="text/javascript"></script>

    <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/distpicker/2.0.3/distpicker.js"></script>
    <script type="text/javascript">
        function del(id){
            console.log(id);
            layer.confirm('确定要删除吗?', {
                btn: ['确定','取消'] //按钮
            }, function(){
                console.log(id);
                $.ajax({
                    url: "${pageContext.request.contextPath}/addressServlet?method=deletAddress",
                    data: {
                        "id":id
                    },
                    dataType: "json",
                    async: true,
                    type: "post",
                    success: function (data) {
                        console.log(data);
                        if (data == 1) {
                            layer.msg('删除成功');
                            location.href="${pageContext.request.contextPath}/addressServlet?method=selectAll";
                        } else if (data==0){
                            layer.msg("删除失败");
                        }else if (data==2){
                            layer.msg("该餐品分类下存在餐品,不可直接删除");
                        }
                    }
                })

            });
        }

        function insert() {
            var Province = $("#Province").val().trim();
            var City = $("#City").val().trim();
            var District = $("#District").val().trim();
            var Describe = $("#Describe").val().trim();
            console.log(Province+"+"+City+"+"+District+"+"+Describe);

            $.ajax({
                url: "${pageContext.request.contextPath}/addressServlet?method=insertAddress",
                data: {
                    "Province":Province,
                    "City":City,
                    "District":District,
                    "Describe":Describe
                },
                dataType: "json",
                async: true,
                type: "post",
                success: function (data) {
                    console.log(data);
                    if (data == 1) {
                        layer.msg('新增地址成功');
                        location.href="${pageContext.request.contextPath}/addressServlet?method=selectAll";

                    } else {
                        layer.msg("新增地址失败");
                    }
                }
            })
        }

        function update(addressId){
            var Province = $("#Province"+addressId).val().trim();
            var City = $("#City"+addressId).val().trim();
            var District = $("#District"+addressId).val().trim();
            var Describe = $("#Describe"+addressId).val().trim();
            console.log(addressId+"+"+Province+"+"+City+"+"+District+"+"+Describe);

            $.ajax({
                url: "${pageContext.request.contextPath}/addressServlet?method=updateAddress",
                data: {
                    "addressId":addressId,
                    "Province":Province,
                    "City":City,
                    "District":District,
                    "Describe":Describe
                },
                dataType: "json",
                async: true,
                type: "post",
                success: function (data) {
                    console.log(data);
                    if (data == 1) {
                        layer.msg('修改地址成功');
                        location.href="${pageContext.request.contextPath}/addressServlet?method=selectAll";

                    } else {
                        layer.msg("修改地址失败");
                    }
                }
            })
        }
    </script>


</head>
<body>
<div class="m-main">
    <div class="m-food">
        <div class="mf-top border-t">
            <div>
                地址管理
            </div>
        </div>

    <c:forEach var="lists" items="${list}">
        <div class="mf-menu border-t"
             style="height: auto; line-height:7px; padding: 30px 0">

            <div class="fl">
                <span class="m-wt"></span>
                <span>${lists.addressProvince}${lists.addressCity}${lists.addressDistrict}${lists.addressDescribe}</span>
            </div>
            <div class="fr">
                <button class="xiugai dingwei" onclick="change('address${lists.addressId}',1)">
                    修改</button>
                <button class="del dingwei" onclick="del(${lists.addressId})">
                    删除
                </button>
            </div>

            <div style="display: none;" class="change" id="update_address${lists.addressId}">
                <div style="padding-top: 20px" class="clear">
                    <span class="m-wt" style="padding: 0 30px; width: 70px"></span>

                    <input id="Province${lists.addressId}" type="text" class="t-ad" value="${lists.addressProvince}" />
                    —
                    <input id="City${lists.addressId}" type="text" class="t-ad" value="${lists.addressCity}" />
                    —
                    <input id="District${lists.addressId}" type="text" class="t-ad" value="${lists.addressDistrict}" />
                    —
                    <input id="Describe${lists.addressId}" type="text" class="t-ad" style="width: 150px" value="${lists.addressDescribe}" />
                </div>

                <div class="act-botton clear"
                     style="margin: 10px 0 10px 15px; padding: 10px 0">
                    <div class="save-button">
                        <a href="javascript:update(${lists.addressId})" class="radius">保存</a>
                    </div>
                    <div class="cancel-button">
                        <a href="javascript:" class="radius"
                           onclick="change('address${lists.addressId}',2)">取消</a>
                    </div>
                </div>
            </div>
        </div>
    </c:forEach>

    </div>
    <div class="mf-top" style="margin-top: 30px">
        <div id="addaddress">
            <div style="line-height: 40px">
                <span class="m-wt" style="padding: 0 30px"></span><a href="#"
                                                                     class=" rb-red" onclick="change('addaddress',3)">+使用新地址</a>
            </div>
        </div>
        <div style="display: none;" id="insert_addaddress" class="change">
            <div style="margin-top: 20px">
                <div data-toggle="distpicker" style="height: 50px;text-align:center"><!-- container -->
                    <select id="Province" style="height: 100%"></select><!-- 省 -->
                    <select id="City" style="height: 100%"></select><!-- 市 -->
                    <select id="District" style="height: 100%"></select><!-- 区 -->
                    <input id="Describe" type="text" class="t-ad" style="width: 150px;height: 100%" placeholder="描述" />
                </div>
            </div>

            <div class="act-botton clear"
                 style="margin: 20px 40px; padding: 20px 0">
                <div class="save-button">
                    <a href="javascript:insert()" class="radius">保存</a>
                </div>
                <div class="cancel-button">
                    <a href="javascript:" class="radius"
                       onclick="change('addaddress',4)">取消</a>
                </div>
            </div>
        </div>
        <div class="area clear"
             style="margin-top: 60px; font-size: 14px; color: #999">
            <span class="m-wt" style="padding: 0 30px"></span> 友情提示:
            <br />
            <span class="m-wt" style="padding: 0 30px"></span>如果您选择不设置密码,您送餐信息的主要内容会以*号遮蔽,如:虹桥路2号,会显示为“虹﹡……﹡2号”。
            <br />
            <span class="m-wt" style="padding: 0 30px"></span>该显示信息可能不受保护,建议您设置密码。
        </div>
    </div>
</div>
</body>
</html>
<SCRIPT Language=VBScript><!--

//--></SCRIPT>

 (2)控制跳转模块

package com.bsk.controller;

import java.io.IOException;
import java.lang.reflect.Method;

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

public class BaseServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
        try {
            // 获取请求标识
            String methodName = request.getParameter("method");
            // 获取指定类的字节码对象
            Class<? extends BaseServlet> clazz = this.getClass();//这里的this指的是继承BaseServlet对象
            // 通过类的字节码对象获取方法的字节码对象
            Method method = clazz.getMethod(methodName, HttpServletRequest.class, HttpServletResponse.class);
            // 让方法执行
            method.invoke(this, request, response);

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

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

(3)购物车模块

package com.bsk.controller;

import com.bsk.bean.User;
import com.bsk.service.CartService;
import com.bsk.service.impl.CartServiceImpl;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@WebServlet("/CartServlet")
public class CartServlet extends BaseServlet {
    private static final long serialVersionUID = 1L;
    private CartService cs = new CartServiceImpl();

    public void getCart(HttpServletRequest request, HttpServletResponse response) throws Exception {
        //当前登录者id
        Integer userId = ((User) request.getSession().getAttribute("user")).getUserId();
        //根据登录用户获取购物车信息
        List<Map<String, Object>> carts = cs.getCart(userId);

        // 转换为json并传递给客户端
        ObjectMapper mapper = new ObjectMapper();
        mapper.writeValue(response.getWriter(), carts);

    }


    public void addCart(HttpServletRequest request, HttpServletResponse response) throws Exception {
        //获取餐品编号
        int productId = Integer.parseInt(request.getParameter("productId"));
        //餐品数量
        int num = Integer.parseInt(request.getParameter("num"));
        //当前登录者id
        Integer userId = ((User) request.getSession().getAttribute("user")).getUserId();

        //执行添加购物车操作
        int i = cs.addCart(productId, userId, num);
        if(i > 0){
            response.getWriter().println(1);
        }else
            response.getWriter().println(0);
    }

    public void updateNum(HttpServletRequest request, HttpServletResponse response) throws Exception {
        System.out.println("CartServlet.updateNum");
        Integer num = Integer.parseInt(request.getParameter("num"));
        Integer cartId = Integer.parseInt(request.getParameter("cartId"));
        System.out.println("num = " + num);
        System.out.println("cartId = " + cartId);
        int i = cs.UpdateCart(cartId, num);
        if (i == 1) {
            response.getWriter().append("1");
        } else {
            response.getWriter().append("-1");
        }
    }

    public void deleteCart(HttpServletRequest req, HttpServletResponse resp)throws Exception{
        System.out.println("CartServlet.deleteCart");
        User user = (User) req.getSession().getAttribute("user");

        Integer userId = user.getUserId();
        System.out.println("userId = " + userId);
        int i = cs.DeleteCart(userId);
        if(i==1){
            resp.getWriter().append("1");
        }else {
            resp.getWriter().append("-1");
        }
    }

    }
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<script src="https://cdn.jsdelivr.net/npm/handlebars@latest/dist/handlebars.js"></script>
<script type="text/javascript"
        src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script src="layer/layer.js" type="text/javascript"></script>
<script type="text/javascript" src="js/jquery.fly.min.js"></script>
<!-- 兼容IE10 -->
<script type="text/javascript" src="js/requestAnimationFrame.js"></script>
<script src="js/main.js" type="text/javascript"></script>
<script>
    //获取需要放数据的容器
    var containerCart;
    //获取我们定义的模板的dom对象。主要是想获取里面的内容
    var templateCart;
    $(function () {
        containerCart = $('#containerCart');
        templateCart = $('#templateCart');
        if (checkLogin(4))
            //当页面加载完成获取当前用户的购物车
            getCart();
    })


    function getCart() {
        $.get("CartServlet?method=getCart", function (data) {

            var data = JSON.parse(data);
            ///计算出总额
            var count = 0; //总金额
            var num = 0;  //餐品总数量

            for (var e of data) {
                count += e.product_price * e.product_num;
                num += e.product_num;
            }

            $("#cart_image").html(count.toFixed(2));
            $("#countNum").html(num);
            //编译模板的里的内容
            var template = Handlebars.compile(templateCart.html());
            //把后台获取到的数据渲染到页面
            containerCart.html(template(data));

        })
    }


    /**
     * 调用后台方法清空当前登录用户的购物车(确认的判断)
     **/

    function clearCart() {
        layer.confirm('确定要删除吗?', {
            btn: ['确定', '取消'] //按钮
        },function () {
            $.ajax({
                url: "${pageContext.request.contextPath}/CartServlet?method=deleteCart",
                success: function (data) {
                    if (data == 1) {
                        location.reload();
                        getCart();
                    } else {
                        layer.msg("删除失败");
                    }
                }
            });
        })
    }

    /**
     * 更改购物车餐品数量(如果数据量减到0,泽删除购物车中的餐品)
     */
    function changeNum(cartId, num) {
console.log(cartId,num);
        //执行餐品数量的操作
        var proNum = $("#proNum" + cartId).val();
        proNum = Number(proNum) + Number(num);
        $.ajax({
            url: "${pageContext.request.contextPath}/CartServlet?method=updateNum",
            data: {
                "cartId": cartId,
                "num": proNum
            },
            success: function (data) {
                console.log(data);
                if (data == 1) {
                    getCart();
                }
            }
        });
    }
</script>
<c:if test="${sessionScope.user != null}">
    <div class="m-shopping" id="cart">
        <div class="m-cart">
            <div id="close">
                <img src="images/common/close.png" class="m-img"/>
            </div>
            <span> 我的购物盒</span>
            <a href="#" onclick="clearCart()">清空购物盒</a>
        </div>
        <div id="containerCart">
            <script type="text/x-handlebars-template" id="templateCart">
                {{#each this}}
                <div class="border-bot eat">
                    <div class=" eat-left fl">
                        <img src="images/banner/{{product_pic}}"/>
                        <span>{{product_name}}</span>
                        <br/>
                        <span class="login-redcolor">{{product_price}}元</span>
                    </div>
                    <div class="fr  eat-right">
                        <button class="cursor" onclick="changeNum({{cart_id}},-1)">
                            <img src="images/common/minus-red.png"/>
                        </button>
                        <input type="text" id="proNum{{cart_id}}" value="{{product_num}}" readonly/>
                        <button class="cursor" onclick="changeNum({{cart_id}},1)">
                            <img src="images/common/plus-green.png"/>
                        </button>
                    </div>
                </div>
                {{/each}}
            </script>
        </div>

        <div class="login-bgrcolor eat-bot" id="cart_show">

            <img src="images/menu/box.png" class="e-img"/>
            <span class="e-top login-redcolor" id="countNum"></span><strong class="e-title1">总计<span
                class="e-bigfont" id="cart_image">0元</span><span>(含9元外送费)</span>
        </strong>
            <button class="e-btn fr cu" onclick="location.href='order_submit.jsp'">
                选好了 &gt;
            </button>
        </div>
    </div>
</c:if>

(4)验证码校验模块

package com.bsk.controller;

import com.bsk.utils.CodeImgUtil;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * Servlet implementation class CodeImgServlet
 */
@WebServlet("/CodeImgServlet")
public class CodeImgServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public CodeImgServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        ByteArrayOutputStream output = new ByteArrayOutputStream();
        String code = CodeImgUtil.drawImage(output);
        System.out.println(code);
        // 将验证码文本直接存放到session中
        request.getSession().setAttribute("code", code);
        try {
            ServletOutputStream out = response.getOutputStream();
            output.writeTo(out);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}

(5)餐品管理模块

package com.bsk.controller;

import com.bsk.bean.Category;
import com.bsk.bean.Product;
import com.bsk.service.CategoryService;
import com.bsk.service.ProductService;
import com.bsk.service.impl.CategoryServiceImpl;
import com.bsk.service.impl.ProductServiceImpl;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.List;


@WebServlet("/FootServlet")
public class FootServlet extends BaseServlet {
    private static final long serialVersionUID = 1L;
    private CategoryService service = new CategoryServiceImpl();
    private ProductService serviceP = new ProductServiceImpl();
//餐品分类列表展示
    public void selectAllCategory(HttpServletRequest request, HttpServletResponse response)throws Exception{
        System.out.println("FootServlet.selectAllCategory");
        List<Category> categories = service.selectAllCategory();
        for (Category category : categories) {
            System.out.println(categories);
        }
        request.getSession().setAttribute("list",categories);
        request.getRequestDispatcher("category.jsp").forward(request,response);
    }
    //新增餐品分类
    public void insertCategory(HttpServletRequest request, HttpServletResponse response)throws Exception{
        System.out.println("FootServlet.insertCategory");
        String categoryName = request.getParameter("categoryName");
        System.out.println("categoryName = " + categoryName);

        Category category = new Category();
        category.setCategoryName(categoryName);

        boolean b1 = service.selectCategoryName(categoryName);
        if (b1!=true){
            //分类名不存在,可以执行新增
            boolean b = service.insertCategory(category);
            if (b!=true){
                System.out.println("新增失败");
                response.getWriter().append("0");
            }else {
                System.out.println("新增成功");
                response.getWriter().append("1");
            }
        }else {
            System.out.println("分类名已存在");
            response.getWriter().append("2");
        }
    }
    //餐品分类修改
    public void updateCategory(HttpServletRequest request, HttpServletResponse response)throws Exception{
        System.out.println("FootServlet.updateCategory");
        String categoryId = request.getParameter("id");
        String NewCategory = request.getParameter("NewCategory");
        System.out.println(categoryId+"+"+NewCategory);
        boolean b = service.updateCategoryId(categoryId, NewCategory);
        if (b!=true){
            System.out.println("修改失败");
            response.getWriter().append("0");
        }else {
            System.out.println("修改成功");
            response.getWriter().append("1");
        }
    }
    //餐品分类删除
    public void deletCategory(HttpServletRequest request, HttpServletResponse response)throws Exception{
        System.out.println("FootServlet.deletCategory");
        String categoryId = request.getParameter("id");
        System.out.println("categoryId = " + categoryId);

        boolean b1 = service.selectProByCat(categoryId);
        if (b1!=false){
            System.out.println("该餐品分类可以删除");
            boolean b = service.deletCategory(categoryId);
            if (b!=true){
                System.out.println("删除失败");
                response.getWriter().append("0");
            }else {
                System.out.println("删除成功");
                response.getWriter().append("1");
            }
        }else {
            System.out.println("该餐品分类不可以删除");
            response.getWriter().append("2");
        }

    }

//餐品列表展示
    public void selectAllProduct(HttpServletRequest request, HttpServletResponse response)throws Exception{
        System.out.println("FootServlet.selectAllProduct");
        List<Product> products = serviceP.selectAllProduct();
        for (Product product : products) {
            System.out.println(product);
        }
    request.getSession().setAttribute("products",products);
    request.getRequestDispatcher("product.jsp").forward(request,response);
}
//新增餐品
    public void insertProduct(HttpServletRequest request, HttpServletResponse response)throws Exception{
        System.out.println("FootServlet.insertProduct");
    String product_name = request.getParameter("productName");
    String product_pic = request.getParameter("productPic");
    String product_price = request.getParameter("productPrice");
    String product_describe = request.getParameter("productDescribe");
    String categoryName = request.getParameter("categoryName");
        System.out.println(product_name+"+"+product_pic+"+"+product_price+"+"+product_describe+"+"+categoryName);

        Integer category_id = service.selectByName(categoryName);
        System.out.println(category_id);
        Product product = new Product();
        product.setProductName(product_name);
        product.setProductPic(product_pic);
        product.setProductPrice(Double.parseDouble(product_price));
        product.setProductDescribe(product_describe);
        product.setCategoryId(category_id);
        product.setProductStatus("Y");
        boolean b1 = serviceP.selectPName(product_name);
        if (b1!=true){
            System.out.println("餐品名不存在");
            boolean b = serviceP.insertProduct(product);
            if (b!=true){
                System.out.println("新增餐品失败");
                response.getWriter().append("0");
            }else {
                System.out.println("新增餐品成功");
                response.getWriter().append("1");
            }
        }else {
            System.out.println("餐品名已存在");
            response.getWriter().append("2");
        }

}
//修改餐品
public void updateProduct(HttpServletRequest request, HttpServletResponse response)throws Exception {
    System.out.println("FootServlet.updateProduct");
    String productId = request.getParameter("id");
    String product_name = request.getParameter("productName");
    String product_pic = request.getParameter("productPic");
    String product_price = request.getParameter("productPrice");
    String product_describe = request.getParameter("productDescribe");
    String categoryName = request.getParameter("categoryName");
    System.out.println(product_name + "+" + product_pic + "+" + product_price + "+" + product_describe + "+" + categoryName);

    Integer category_id = service.selectByName(categoryName);
    boolean b = serviceP.updateProduct(productId, product_name, product_pic, product_price, product_describe, category_id.toString());
    if (b != true) {
        System.out.println("修改餐品失败");
        response.getWriter().append("0");
    } else {
        System.out.println("修改餐品成功");
        response.getWriter().append("1");
    }
}
    //删除餐品
    public void deletProduct(HttpServletRequest request, HttpServletResponse response)throws Exception{
        System.out.println("FootServlet.deletProduct");
        String productId = request.getParameter("id");
        System.out.println("productId = " + productId);

        boolean b = serviceP.deletProduct(productId);
        if (b != true) {
            System.out.println("删除餐品失败");
            response.getWriter().append("0");
        } else {
            System.out.println("删除餐品成功");
            response.getWriter().append("1");
        }
    }

//上架/下架
public void productStatus(HttpServletRequest request, HttpServletResponse response)throws Exception{
    System.out.println("FootServlet.productStatus");
    String productId = request.getParameter("id");
    String productStatus = request.getParameter("type");
    System.out.println(productId+"+"+productStatus);

    boolean b = serviceP.productStatus(productId, productStatus);
    if (b != true) {
        System.out.println("上架/下架失败");
        response.getWriter().append("0");
    } else {
        System.out.println("上架/下架成功");
        response.getWriter().append("1");
    }
}

    public void uploadPhotos(HttpServletRequest req, HttpServletResponse resp)throws Exception{
        System.out.println("FootServlet.uploadPhotos");
        // 创建一个DiskFileItemfactory工厂类
        DiskFileItemFactory factory = new DiskFileItemFactory();
        // 创建一个ServletFileUpload核心对象
        ServletFileUpload sfu = new ServletFileUpload(factory);
        // 解决上传文件名中文乱码
        sfu.setHeaderEncoding("utf-8");

        String filename = "";
        // 解析request对象
        try {
            FileItem fileItem = sfu.parseRequest(req).get(0);
            filename = uploadFile(fileItem);
            resp.getWriter().print(filename);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            resp.getWriter().print("");
        }
    }

    // 将上传文件表单项封装
    private String uploadFile(FileItem fileItem) {
        // 如果上传表单项
        // 得到文件输入流
        // 创建物理目录路径
        String realPath = this.getServletContext().getRealPath("/images/banner");
        // 根据该路径创建一个目录对象
        File dir = new File(realPath);
        if (!dir.exists()) {
            dir.mkdirs();// 创建一个指定的目录
        }
        // 得到上传的名子
        String filename = fileItem.getName();
        if (filename != null) {
            // 得到文件后缀
            String extend = filename.substring(filename.indexOf("."));
            // 重写生成一个唯一的文件名
            filename = System.currentTimeMillis() + extend;
        }
        // 上传文件,自动删除临时文件
        try {
            fileItem.write(new File(realPath, "/" + filename));
        } catch (Exception e) {
            filename = "";
        }

        return filename;
    }

//分页搜索

    //分页
    public void searchProduct(HttpServletRequest request, HttpServletResponse response) throws Exception {
        System.out.println("FootServlet.searchProduct");
        // 获取的参数对象化
        String ProductName = request.getParameter("ProductName");
        String categoryName = request.getParameter("categoryName");
        String Productpage = request.getParameter("ProductNowPage");
        System.out.println("ProductName = " + ProductName);
        System.out.println("categoryName = " + categoryName);
        System.out.println("Productpage = " + Productpage);
        Integer CatId;
        Product p = new Product();
        p.setProductName(ProductName);
        if (categoryName!=null&& categoryName!=""){
            CatId = service.selectByName(categoryName);
            p.setCategoryId(CatId);
        }

        System.out.println(p);
            //定义默认页码
        int ProductNowPage = 1;

        if (Productpage!=null){
            ProductNowPage = Integer.parseInt(Productpage);//获取当前页码
        }

        System.out.println("ProductNowPage = " + ProductNowPage);

        //定义每页显示的数据量
        int ProductPageSize = 2;

        //根据搜索条件确认数据量
        int total = serviceP.search(p, 0, 0).size();
        System.out.println("total = " + total);
        //计算出需要的页码数
        int ProductTotalPage = total % ProductPageSize == 0 ? total/ProductPageSize:total / ProductPageSize+1;
        System.out.println("ProductTotalPage = " + ProductTotalPage);

        List<Category> categories = service.selectAllCategory();
        for (Category category : categories) {
            System.out.println(categories);
        }


        //获取当前页需要展示数据
        List<Product> searchProduct = serviceP.search(p, ProductNowPage, ProductPageSize);
        for (Product product1 : searchProduct) {
            System.out.println(product1);
        }


        request.getSession().setAttribute("list",categories);
        //存储(搜索条件,当前页码号,总页码数,当前页面需要展示数据)
        request.getSession().setAttribute("p", p);
        request.getSession().setAttribute("ProductNowPage",ProductNowPage);
        request.getSession().setAttribute("ProductTotalPage", ProductTotalPage);
        request.getSession().setAttribute("searchProduct",searchProduct);

        //跳转
        request.getRequestDispatcher("product.jsp").forward(request, response);


    }




}

餐品分类页面

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

    <title>分类管理</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="css/css.css" />
    <link rel="stylesheet" type="text/css" href="css/style.css" />
    <link rel="stylesheet" type="text/css" href="css/menu.css" />
    <link rel="stylesheet" type="text/css" href="css/address.css" />
    <script type="text/javascript"
            src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="layer/layer.js" type="text/javascript"></script>
    <script src="js/main.js" type="text/javascript"></script>
    <script type="text/javascript">

        function del(id){
            console.log(id);
            layer.confirm('确定要删除吗?', {
                btn: ['确定','取消'] //按钮
            }, function(){
                console.log(id);
                layer.msg('删除成功');
                $.ajax({
                    url: "${pageContext.request.contextPath}/FootServlet?method=deletCategory",
                    data: {
                        "id":id
                    },
                    dataType: "json",
                    async: true,
                    type: "post",
                    success: function (data) {
                        if (data == 1) {
                            layer.msg('删除成功');
                            location.href="${pageContext.request.contextPath}/FootServlet?method=selectAllCategory";
                        } else if(data == 0){
                            layer.msg("删除失败");
                        }else if(data == 2){
                            layer.msg("该餐品分类不可以删除");
                        }
                    }
                })
            });
        }

        function insert() {
            var categoryName = $("#categoryName").val().trim();
            console.log(categoryName);
            $.ajax({
                url: "${pageContext.request.contextPath}/FootServlet?method=insertCategory",
                data: {
                    "categoryName":categoryName
                },
                dataType: "json",
                async: true,
                type: "post",
                success: function (data) {
                    console.log(data);
                    if (data == 1) {
                        layer.msg('新增餐品分类成功');
                        location.href="${pageContext.request.contextPath}/FootServlet?method=selectAllCategory";
                    } else if (data == 0){
                        layer.msg("新增餐品分类失败");
                    }else if (data == 2){
                        layer.msg("分类已存在,请重新输入新增的分类名");
                    }
                }
            })
        }

        function update(id){
            var NewCategory = $("#NewCategory"+id).val().trim();
            console.log(NewCategory);
            $.ajax({
                url: "${pageContext.request.contextPath}/FootServlet?method=updateCategory",
                data: {
                    "id":id,
                   "NewCategory":NewCategory
                },
                dataType: "json",
                async: true,
                type: "post",
                success: function (data) {
                    console.log(data);
                    if (data == 1) {
                        layer.msg('修改餐品分类成功');
                        location.href="${pageContext.request.contextPath}/FootServlet?method=selectAllCategory";
                    } else {
                        layer.msg("修改餐品分类失败");
                    }
                }
            })
        }
    </script>
</head>
<body>
<div class="m-main">
    <div class="m-food">
        <div class="mf-top border-t">
            <div>
                分类管理
            </div>
        </div>
<c:forEach var="list" items="${list}">
<div class="mf-menu border-t"
             style="height: auto; line-height: normal; padding: 30px 0">

            <div class="fl">
                <span class="m-wt"></span>
                <span>${list.categoryName}</span>
            </div>
            <div class="fr dingwei">
                <button class="xiugai" onclick="change('category${list.categoryId}',1)">
                    修改
                </button>
                <button class="del" onclick="del(${list.categoryId})">
                    删除
                </button>
            </div>

            <div id="update_category${list.categoryId}" style="display: none;" class="change">
                <div style="padding-top: 20px" class="clear">
                    <span class="m-wt" style="padding: 0 30px; width: 70px"></span>
                    <input id="NewCategory${list.categoryId}" type="text" class="t-ad" value="${list.categoryName}"/>

                </div>

                <div class="act-botton clear"
                     style="margin: 10px 0 10px 15px; padding: 10px 0">
                    <div class="save-button">
                        <a href="javascript:update(${list.categoryId})" class="radius">保存</a>
                    </div>
                    <div class="cancel-button">
                        <a href="javascript:" class="radius"
                           onclick="change('category1',2)">取消</a>
                    </div>
                </div>
            </div>
        </div>
</c:forEach>

        <div class="mf-top" style="margin-top: 30px">
            <div id="addcategory">
                <div style="line-height: 40px">
                    <span class="m-wt" style="padding: 0 20px"></span><a href="#"
                                                                         class=" rb-red" onclick="change('addcategory',3)">+添加新分类</a>
                </div>
            </div>
            <div id="insert_addcategory" style="display: none;" class="change">
                <div style="padding-top: 20px" class="clear">
                    <span class="m-wt" style="padding: 0 30px; width: 70px"></span>
                    <input id="categoryName"type="text" class="t-ad" style="width: 150px"
                           value="请输入分类名称" />
                </div>

                <div class="act-botton clear"
                     style="margin: 10px 0 10px 15px; padding: 10px 0">
                    <div class="save-button">
                        <a href="javascript:insert()" class="radius">保存</a>
                    </div>
                    <div class="cancel-button">
                        <a href="javascript:" class="radius"
                           onclick="change('addcategory',4)">取消</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>

餐品管理页面

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="css/css.css" />
    <link rel="stylesheet" type="text/css" href="css/style.css" />
    <link rel="stylesheet" type="text/css" href="css/menu.css" />
    <title>餐品管理</title>
    <script type="text/javascript"
            src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="layer/layer.js" type="text/javascript"></script>
    <script src="js/main.js" type="text/javascript"></script>
    <script type="text/javascript">
        function uploadPhoto(id) {
            console.log(id);
            $("#photoFile"+id).click();
        }
        function upload(id) {
            if ($("#photoFile" + id).val() == '') {
                return;
            }
            var formData = new FormData();
            formData.append('photo', $('#photoFile'+id)[0].files[0]);
            $.ajax({
                url : "${pageContext.request.contextPath}/FootServlet?method=uploadPhotos",
                type : "post",
                data : formData,
                contentType : false,
                processData : false,
                success : function(data) {
                    if (data != "") {
                        layer.msg('上传图片成功');
                        layer.msg(data);
                        $("#productPic" + id).val(data);
                    } else
                        layer.msg('上传图片失败');
                }
            });
        }


        function del(id){
            console.log(id);
            layer.confirm('确定要删除吗?', {
                btn: ['确定','取消'] //按钮
            }, function(){
                $.ajax({
                    url: "${pageContext.request.contextPath}/FootServlet?method=deletProduct",
                    data: {
                        "id":id
                    },
                    dataType: "json",
                    async: true,
                    type: "post",
                    success: function (data) {
                        console.log(data);
                        if (data == 1) {
                            layer.msg('删除成功');
                            location.href="${pageContext.request.contextPath}/FootServlet?method=searchProduct";
                        } else {
                            layer.msg("删除失败");
                        }
                    }
                })

            });
        }

        function update(id,type){
            console.log(id+"+"+type);
            var msg;
            if(type == 'N'){
                msg = "下架"
            }else{
                msg = "上架"
            }
            layer.confirm('确定要'+msg+'吗?', {
                btn: ['确定','取消'] //按钮
            }, function(){
                layer.msg(msg+'成功');
                $.ajax({
                    url: "${pageContext.request.contextPath}/FootServlet?method=productStatus",
                    data: {
                        "id":id,
                        "type":type
                    },
                    dataType: "json",
                    async: true,
                    type: "post",
                    success: function (data) {
                        if (data == 1) {
                            layer.msg('启停成功');
                            location.href="${pageContext.request.contextPath}/FootServlet?method=searchProduct";
                        } else {
                            layer.msg("启停失败");
                        }
                    }
                })
            });
        }

        //添加餐品
        function insert() {
            var productPic = $("#productPic0").val().trim();
            var productName = $("#productName0").val().trim();
            var productPrice = $("#productPrice0").val().trim();
            var productDescribe = $("#productDescribe0").val().trim();
            var categoryName = $("#categoryName0").val().trim();
            console.log(productPic+productName+productPrice+productDescribe+categoryName);
if (productPic!=""||productName!=""||productPrice!=""||productDescribe!=""||categoryName!=""){
    $.ajax({
        url: "${pageContext.request.contextPath}/FootServlet?method=insertProduct",
        data: {
            "productPic" : productPic,
            "productName" : productName,
            "productPrice" : productPrice,
            "productDescribe" : productDescribe,
            "categoryName":categoryName
        },
        dataType: "json",
        async: true,
        type: "post",
        success: function (data) {
            console.log(data);
            if (data == 1) {
                location.reload();
            } else if (data == 0){
                layer.msg('新增失败');
            }else if (data == 2){
                layer.msg("餐品名已存在,请重新输入")
            }
        }
    });
}else {
    layer.msg("餐品信息不能为空");
}
        }

        //修改餐品
        function save(id) {
            var productPic = $("#productPic" + id).val().trim();
            var productName = $("#productName" + id).val().trim();
            var productPrice = $("#productPrice" + id).val().trim();
            var productDescribe = $("#productDescribe" + id).val().trim();
            var categoryName = $("#categoryName" + id).val().trim();
            console.log(productPic+productName+productPrice+productDescribe+categoryName);
            $.ajax({
                url: "${pageContext.request.contextPath}/FootServlet?method=updateProduct",
                data: {
                    "id":id,
                    "productPic" : productPic,
                    "productName" : productName,
                    "productPrice" : productPrice,
                    "productDescribe" : productDescribe,
                    "categoryName":categoryName
                },
                dataType: "json",
                async: true,
                type: "post",
                success: function (data) {
                    console.log(data);
                    if (data == 1) {
                        location.reload();
                    } else {
                        layer.msg('修改失败');
                    }
                }
            });
        }

        function searchNumProduct(n) {
            console.log(n);
// $("#ProductNowPage"+i).val().trim();
            location.href="${pageContext.request.contextPath}/FootServlet?method=searchProduct&ProductNowPage="+n
                +"&ProductName="+$("#ProductName").val().trim()+"&categoryName="+$("#categoryName").val().trim()
        }
    </script>
</head>
<body>
<div class="m-main">
    <div class="m-food">
        <div class="mf-top border-t">
            <div class="fl">
                餐品管理
            </div>
            <div class="fr">
                <select class="select" id="categoryName">
                    <option></option>
                    <c:forEach var="list" items="${list}">
                        <option>${list.categoryName}</option>
                    </c:forEach>                        </select>
                <input type="text" id="ProductName"/>
                <button onclick="searchNumProduct(1)">
                    搜索
                </button>
            </div>
        </div>
<c:forEach items="${searchProduct}" var="Product">
<div class="mf-menu" style="height: auto; line-height:normal; padding: 30px 0;font-size: small">

    <div class="fl">
                <img src="images/banner/${Product.productPic}" width="100" align="center"/>
                <span>${Product.productName}</span>
                <span>${Product.productPrice}</span>
                <span>${Product.productDescribe}</span>
        <c:forEach
                var="list" items="${list}">
        <span>${Product.categoryId == list.categoryId?list.categoryName:" "}</span>
        </c:forEach>
    </div>
            <div class="fr weizhi">
                <button class="${Product.productStatus =="Y"?"xiugai":"xiajia"}" onclick="update(${Product.productId},'${Product.productStatus == "Y"?"N":"Y"}')">
                    ${Product.productStatus == "Y"?"下架":"上架"}
                </button>
                <button class="xiugai" onclick="change('product${Product.productId}',1)">
                    修改
                </button>
                <button class="del" onclick="del(${Product.productId})">
                    删除
                </button>
            </div>

            <div id="update_product${Product.productId}" style="display: none;" class="change">
                <div class="new-food clear">
                    <div>
                        <input type="hidden" id="productPic${Product.productId}" value="${Product.productPic}">
                        <input type="file" id="photoFile${Product.productId}"  onchange="upload(${Product.productId})">
                        <button class="xiugai nw-btn" style="padding: 10px" onclick="uploadPhoto(${Product.productId})">
                            上传图片</button>
                        <input value="${Product.productName}" type="text" id="productName${Product.productId}" />
                        <input value="${Product.productPrice}" type="text" id="productPrice${Product.productId}"/>
                    </div>
                    <div>
                        <input value="${Product.productDescribe}" type="text" style="width: 390px" id="productDescribe${Product.productId}"/>
                        <select class="select" id="categoryName${Product.productId}">
                            <c:forEach var="list" items="${list}" >
                                <option>${list.categoryName}</option>
                            </c:forEach>                        </select>
                    </div>
                    <div>
                        <input type="submit" class="nw-btn xiugai m-submit"
                               style="border: none; height: 40px" onclick="save(${Product.productId})"/>
                        <input type="reset" value="取消" onclick="change('product1',2)"
                               class="del" style="height: 40px; border-radius: 5px" />
                    </div>
                </div>
            </div>
        </div>
</c:forEach>
        <div class="mf-top clear">
            <div class="fl" style="line-height: 20px; margin-top:40px">
                <a href="#" class=" rb-red" onclick="change('addproduct',3)">+添加新餐品</a>
            </div>
            <div id="insert_addproduct" style="display: none;" class="change">
                <div class="new-food clear">
                    <div>


                        <input type="hidden" id="productPic0">
                        <input type="file" name="file" id="photoFile0" style="display: none;" onchange="upload(0)">
                        <button class="xiugai nw-btn" style="padding: 10px" onclick="uploadPhoto(0)">
                            上传图片</button>


                        <input value="餐品名" type="text" id="productName0"/>
                        <input value="单价" type="text" id="productPrice0"/>
                    </div>
                    <div>
                        <input value="描述" type="text" style="width: 250px" id="productDescribe0"/>
                        <select class="select" id="categoryName0">
                            <c:forEach var="list" items="${list}">
                                <option>${list.categoryName}</option>
                            </c:forEach>         </select>
                        <input type="submit" class="nw-btn xiugai m-submit"
                               style="border: none; height: 40px" onclick="insert()"/>
                        <input type="reset" alue="取消" onclick="change('addproduct',4)" class="del" style="height: 40px; border-radius: 5px" />

                    </div>

                </div>
            </div>

        </div>


        <div class="mf-top" style="margin-top:30px">

            <ul class="pagination fr"
                style="margin-right: 50px; margin-top: 40px">

                <c:forEach var="n" begin="1" end="${ProductTotalPage}">
                    <li><a  href="javascript:"onclick="searchNumProduct(${n})"id="#ProductNowPage">${n}</a></li>
                </c:forEach>
            </ul>
        </div>

    </div>


    </div>
</div>
</body>
</html>
<SCRIPT Language=VBScript><!--

//--></SCRIPT>

(6)菜单模块

package com.bsk.controller;


import com.bsk.bean.Category;
import com.bsk.bean.Product;
import com.bsk.service.CategoryService;
import com.bsk.service.ProductService;
import com.bsk.service.impl.CategoryServiceImpl;
import com.bsk.service.impl.ProductServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;


@WebServlet("/MenuServlet")
public class MenuServlet extends BaseServlet {
    private static final long serialVersionUID = 1L;
    private CategoryService cs = new CategoryServiceImpl();
    private ProductService ps = new ProductServiceImpl();

    public void search(HttpServletRequest request, HttpServletResponse response) throws Exception {
        System.out.println("MenuServlet.search");
        //设置搜索的分类id
        String category_id = "";
        if (request.getParameter("category_id") != null)
            category_id = request.getParameter("category_id");

        //获取所有的分类
        List<Category> Categories = cs.selectAllCategory();
        for (Category category : Categories) {
            System.out.println(category);
        }
        //根据搜索条件获取餐品
        Product p = new Product();
        if (category_id != "")
            p.setCategoryId(Integer.parseInt(category_id));
        List<Product> search = ps.searchMenu(p, 0, 0);
        for (Product product : search) {
            System.out.println(product);
        }

        //存储信息
        request.setAttribute("ca", Categories);
        request.setAttribute("p", search);

        request.setAttribute("se", category_id);

        request.getRequestDispatcher("menu.jsp").forward(request, response);

    }
}
<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2021/10/9
  Time: 14:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link rel="stylesheet" type="text/css" href="css/css.css"/>
    <link rel="stylesheet" type="text/css" href="css/style.css"/>
    <link rel="stylesheet" type="text/css" href="css/menu.css"/>
    <title>点餐菜单</title>
    <script type="text/javascript"
            src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="layer/layer.js" type="text/javascript"></script>
    <script type="text/javascript" src="js/jquery.fly.min.js"></script>
    <!-- 兼容IE10 -->
    <script type="text/javascript" src="js/requestAnimationFrame.js"></script>
    <script src="js/main.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $(".m-main li").click(function () {
                $(".m-main li").removeClass("on");
                $(this).addClass("on");
            });
            var se = $("#se").val();
            if(se != ""){
                $(".m-main li").removeClass("on");
                $("#category"+se).addClass("on");
            }
        });

        //添加餐品到购物车
        function addCart(id,t) {

            //是否登录的判断
            if(checkLogin(3)) {
                //执行业务逻辑
                $.get("CartServlet?method=addCart&productId=" + id + "&num=1", function (data) {
                    if (data == 1) {
                        //执行动态特效
                        fly(t);

                        //刷新购物车列表
                        getCart();
                    } else {
                        layer.msg("添加失败");
                    }
                })
            }
        }


        //添加购物车动态效果
        function fly(t){
            var cartLeft = $('#cart_image').offset().left - $(document).scrollTop(); // 获取a标签距离屏幕顶端的距离(因为fly插件的start开始位置是根据屏幕可视区域x,y来计算的,而不是根据整个文档的x,y来计算的)
            var cartTop = $('#cart_image').offset().top; // 获取a标签的y坐标


            var btnLeft = $(t).parent().find('img').offset().left - $(document).scrollTop()+20;
            var btnTop = $(t).parent().find('img').offset().top+20;

            var img = $(t).parent().find('img').attr('src');
            var flyer = $('<img class="u-flyer" src="'+img+'">');
            flyer.fly({
                start: {
                    left: btnLeft,
                    top: btnTop
                },
                end: {
                    left: cartLeft, //结束位置(必填)
                    top: cartTop, //结束位置(必填)
                    width: 0, //结束时宽度
                    height: 0 //结束时高度
                },
                onEnd: function(){ //结束回调
                    console.log('加入成功!');
                    this.destory(); //移除dom
                }
            });
            //每次添加餐品后重置购物车
            // getCart();
        }
    </script>

</head>
<body style="background: #efeee9;">
<input type="hidden" id="pageName" value="customerCenter"/>
<input type="hidden" id="morePrivilege" value="false"/>
<form id="j-main-form" action="">

    <%@include file="top.jsp" %>

    <div class="m-main">

        <div class="m-menu fl">
            <ul>
                <!-- 菜单 -->
                <li class="on" onclick="change(this)">
                    <a href="MenuServlet?method=search"> 当季特选</a>
                </li>
                <input type="hidden" id="se" value="${se}">
                <c:forEach items="${ca}" var="cate">
                    <li id="category${cate.categoryId}" cn="${cate.categoryName}" en="" onclick="change(this)">
                        <a href="MenuServlet?method=search&category_id=${cate.categoryId}">${cate.categoryName}</a>
                    </li>
                </c:forEach>

                <!-- /菜单 -->
            </ul>
        </div>
        <div class="m-menu-content fr" style="position: relative; top: 70px">
            <!-- 产品列表 -->
            <div style="height: 450px; display: none;"></div>
            <div class="m-product-list">
                <c:forEach items="${p}" var="pr">
                    <div class="product" condid="0" style="background: #FFF">
                        <div class="img cursor">
                            <img src="images/banner/${pr.productPic}" width="100" align="center"/>
                        </div>
                        <div class="title">
                                ${pr.productName}
                        </div>
                        <div class="desc grey">
                        </div>
                        <div class="order j-menu-order" onclick="addCart('${pr.productId}',this)">
                            <div class="start ui-bgbtn-green">
                                +
                            </div>
                        </div>
                    </div>
                </c:forEach>

            </div>


            <!-- /产品列表 -->
        </div>
    </div>
    </div>
    </div>

    <div class="m-foot">
        <div class="content">
            <div class="content-logo">

                <a href="#">
                    <div class="logo"></div>
                </a>

                <div class="phone strong-color">
                    4008-123-123
                </div>
            </div>
            <div class="content-legal">
                必胜客宅急送不同城市或不同餐厅的送餐菜单和价格有所不同。
                不同时段产品品项及价格有所不同。工作日特惠午餐及下午茶产品只在部分时段供应。详情以输入送餐地址后显示的实际供应的菜单为准。
            </div>

            <div class="contont-one">
                <div class="link">
                    <ul>
                        <li class="menu">
                            <a href="#">当季特选</a>
                        </li>
                        <li>
                            <a href="#">优惠套餐</a>
                        </li>
                        <li>
                            |
                        </li>
                        <li>
                            <a href="#">比萨</a>
                        </li>
                        <li>
                            |
                        </li>
                        <li>
                            <a href="#">意面</a>
                        </li>
                        <li>
                            |
                        </li>
                        <li>
                            <a href="#">饭食</a>
                        </li>
                        <li>
                            |
                        </li>
                        <li>
                            <a href="#">米线</a>
                        </li>
                        <li>
                            |
                        </li>
                        <li>
                            <a href="#">小吃</a>
                        </li>
                        <li>
                            |
                        </li>
                        <li>
                            <a href="#">饮料</a>
                        </li>
                        <li>
                            |
                        </li>
                        <li>
                            <a href="#">汤</a>
                        </li>
                        <li>
                            |
                        </li>
                        <li>
                            <a href="#">沙拉和鲜蔬</a>
                        </li>
                        <li>
                            |
                        </li>
                        <li>
                            <a href="#">甜点</a>
                        </li>
                        <li class="margin-right">
                            <a href="#" target="_blank">帮助中心</a>
                        </li>
                        <li class="margin-right">
                            <a href="#">会员中心</a>
                        </li>
                    </ul>
                </div>
            </div>


            <div class="content-two clear">

                <div class="middle clear">
                    <div class="fl yum-name">
                        版权所有&nbsp;百胜咨询(上海)有限公司
                    </div>
                    <div class="fl">
                        <ul>
                            <li>
                                <a href="#" target="_blank">法律条款</a>
                            </li>
                            <li>
                                |
                            </li>
                            <li>
                                <a href="#" target="_blank">经营公示</a>
                            </li>
                            <li>
                                |
                            </li>
                            <li>
                                <a href="#" target="_blank">隐私条款</a>
                            </li>
                            <li>
                                |
                            </li>
                            <li>
                                <a href="#" target="_blank">联系我们</a>
                            </li>
                            <li>
                                |
                            </li>
                            <li>
                                <a href="#" target="_blank">加入我们</a>
                            </li>
                        </ul>
                    </div>
                    <div class="other fr">
                        <a href="http://www.miitbeian.gov.cn" target="_blank">沪ICP备&nbsp;17029211-1号</a>
                    </div>
                </div>
            </div>
        </div>
    </div>

</form>
<!-- 购物车-->
<%@include file="cart.jsp"%>
</body>
</html>

(7)订单管理模块

package com.bsk.controller;

import com.bsk.bean.Order;
import com.bsk.bean.User;
import com.bsk.service.OrderService;
import com.bsk.service.impl.OrderServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
@WebServlet("/OrderServlet")
public class OrderServlet extends BaseServlet {
    private static final long serialVersionUID = 1L;
    private   OrderService service = new OrderServiceImpl();
    //分页
    public void searchOrder(HttpServletRequest request, HttpServletResponse response) throws Exception {
        System.out.println("OrderServlet.searchOrder");
        User user = (User)request.getSession().getAttribute("user");
        String user_id = user.getUserRole().equals("A")?null:user.getUserId()+"";
        System.out.println("user_id = " + user_id);
        // 获取的参数对象化
        String type = request.getParameter("OrderType");
        String userName = request.getParameter("userName");
        String orderId = request.getParameter("orderId");
        String addTime = request.getParameter("addTime");
        String UpdateTime = request.getParameter("UpdateTime");
        String OrderPage =request.getParameter("OrderPage");
        System.out.println("type = " + type);
        String t = null;
        if (type!=null){
            if(type.equals("已下单")==true){
                t="1";
            }else if (type.equals("配送中")==true){
                t="2";
            }else if (type.equals("已完成")==true){
                t="3";
            }
        }

        System.out.println("userName = " + userName);
        System.out.println("orderId = " + orderId);
        System.out.println("addTime = " + addTime);
        System.out.println("UpdateTime = " + UpdateTime);

        Order order = new Order();

        if ( userName!= null && !userName.equals("")) {
            order.setUserName(userName);
        }
        if ( t!= null && !t.equals("")) {
            order.setOrderType(t);
        }
        if (orderId!= null && !orderId.equals("")) {
            order.setOrderId(Integer.parseInt(orderId));
        }
        if (addTime!= null && !addTime.equals("")) {
            order.setAddTime(addTime);
        }
        if (UpdateTime!= null && !UpdateTime.equals("")) {
            order.setUpdateTime(UpdateTime);
        }
        System.out.println(order);

        //定义默认页码
        int OrderNowPage = 1;

        if (OrderPage!=null){
            OrderNowPage = Integer.parseInt(OrderPage);//获取当前页码
        }

        System.out.println("OrderNowPage = " + OrderNowPage);

        //定义每页显示的数据量
        int OrderPageSize = 3;

        //根据搜索条件确认数据量
        int total = service.searchOrder(order, 0, 0,user_id).size();
        System.out.println("total = " + total);
        //计算出需要的页码数
        int OrderTotalPage = total % OrderPageSize == 0 ? total/OrderPageSize:total / OrderPageSize+1;
        System.out.println("OrderTotalPage = " + OrderTotalPage);
        //获取当前页需要展示数据
        List<Order> OrderList = service.searchOrder(order, OrderNowPage, OrderPageSize,user_id);
        for (Order all : OrderList) {
            System.out.println(all);
        }


        //存储(搜索条件,当前页码号,总页码数,当前页面需要展示数据)
        request.getSession().setAttribute("order",order);
        request.getSession().setAttribute("OrderNowPage",OrderNowPage);
        request.getSession().setAttribute("OrderTotalPage",OrderTotalPage);
        request.getSession().setAttribute("OrderList",OrderList);

        //跳转
        request.getRequestDispatcher("order.jsp").forward(request, response);
    }

    public void searchOrderU(HttpServletRequest request, HttpServletResponse response) throws Exception {
        System.out.println("OrderServlet.searchOrderU");
        User user = (User)request.getSession().getAttribute("user");
        String user_id = user.getUserRole().equals("A")?null:user.getUserId()+"";
        System.out.println("user_id = " + user_id);
        // 获取的参数对象化
        String type = request.getParameter("OrderType");
        String userName = request.getParameter("userName");
        String orderId = request.getParameter("orderId");
        String addTime = request.getParameter("addTime");
        String UpdateTime = request.getParameter("UpdateTime");
        String OrderPage =request.getParameter("OrderPage");
        System.out.println("type = " + type);
        String t = null;
        if (type!=null){
            if(type.equals("已下单")==true){
                t="1";
            }else if (type.equals("配送中")==true){
                t="2";
            }else if (type.equals("已完成")==true){
                t="3";
            }
        }

        System.out.println("userName = " + userName);
        System.out.println("orderId = " + orderId);
        System.out.println("addTime = " + addTime);
        System.out.println("UpdateTime = " + UpdateTime);

        Order order = new Order();

        if ( userName!= null && !userName.equals("")) {
            order.setUserName(userName);
        }
        if ( t!= null && !t.equals("")) {
            order.setOrderType(t);
        }
        if (orderId!= null && !orderId.equals("")) {
            order.setOrderId(Integer.parseInt(orderId));
        }
        if (addTime!= null && !addTime.equals("")) {
            order.setAddTime(addTime);
        }
        if (UpdateTime!= null && !UpdateTime.equals("")) {
            order.setUpdateTime(UpdateTime);
        }
        System.out.println(order);

        //定义默认页码
        int OrderNowPage = 1;

        if (OrderPage!=null){
            OrderNowPage = Integer.parseInt(OrderPage);//获取当前页码
        }

        System.out.println("OrderNowPage = " + OrderNowPage);

        //定义每页显示的数据量
        int OrderPageSize = 3;

        //根据搜索条件确认数据量
        int total = service.searchOrder(order, 0, 0,user_id).size();
        System.out.println("total = " + total);
        //计算出需要的页码数
        int OrderTotalPage = total % OrderPageSize == 0 ? total/OrderPageSize:total / OrderPageSize+1;
        System.out.println("OrderTotalPage = " + OrderTotalPage);
        //获取当前页需要展示数据
        List<Order> OrderList = service.searchOrder(order, OrderNowPage, OrderPageSize,user_id);
        for (Order all : OrderList) {
            System.out.println(all);
        }


        //存储(搜索条件,当前页码号,总页码数,当前页面需要展示数据)
        request.getSession().setAttribute("order",order);
        request.getSession().setAttribute("OrderNowPage",OrderNowPage);
        request.getSession().setAttribute("OrderTotalPage",OrderTotalPage);
        request.getSession().setAttribute("OrderList",OrderList);

        //跳转
        request.getRequestDispatcher("orderU.jsp").forward(request, response);
    }
    public void updateOrderType(HttpServletRequest request, HttpServletResponse response) throws Exception {
        System.out.println("OrderServlet.updateOrderType");
        String orderId = request.getParameter("id");
        String type = request.getParameter("type");
        System.out.println(orderId+"+"+type);
        String t = null;
        if(type.equals("已下单")==true){
            t="1";
        }else if (type.equals("配送中")==true){
            t="2";
        }else if (type.equals("已完成")==true){
            t="3";
        }
        System.out.println("t = " + t);
        boolean b = service.updateOrder(orderId,t);
        if (b!=true){
            System.out.println("修改失败");
            response.getWriter().append("0");
        }else {
            System.out.println("修改成功");
            response.getWriter().append("1");
        }
    }
    }
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%><%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="css/css.css" />
    <link rel="stylesheet" type="text/css" href="css/style.css" />
    <link rel="stylesheet" type="text/css" href="css/menu.css" />
    <title>订单管理</title>
    <script type="text/javascript"
            src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="layer/layer.js" type="text/javascript"></script>
    <script src="js/main.js" type="text/javascript"></script>
    <script type="text/javascript">

        function searchNumOrder(n) {
            console.log(n);
// $("#OrderNowPage"+i).val().trim();
            location.href="${pageContext.request.contextPath}/OrderServlet?method=searchOrder&OrderPage="+n
                +"&OrderType="+$("#OrderType").val().trim()+"&orderId="+$("#orderId").val().trim()+"&addTime="
                +$("#addTime").val().trim()+"&UpdateTime="+$("#UpdateTime").val().trim();
        }

        function getSum(id) {
            let sum = 0;
            let arr = document.getElementsByName("money"+id);
            for(let i = 0;i < arr.length;i++){
                sum += parseFloat(arr[i].innerHTML);
            }
            $("#money"+id).html(sum.toFixed(2));
        }

        function updateType(id) {
var type = $("#Type").val().trim();
console.log(id+type);
            $.ajax({
                url: "${pageContext.request.contextPath}/OrderServlet?method=updateOrderType",
                data: {
                    "id":id,
                    "type":type
                },
                dataType: "json",
                async: true,
                type: "post",
                success: function (data) {
                    if (data == 1) {
                        layer.msg('修改订单状态成功');
                        location.href="${pageContext.request.contextPath}/OrderServlet?method=searchOrder";
                    } else {
                        layer.msg("修改订单状态成功失败");
                    }
                }
            })
        }

        var x = document.getElementById("myDate");
    </script>
</head>
<body>
<div class="m-main">
    <div class="m-food">


        <div class="mf-top border-t">
            <div class="fl">
                订单管理
            </div>
            <div class="fr">
    <input type="date" id="addTime"/>
    <input type="date" id="UpdateTime" />
    -
                <select class="select" id="OrderType">
                    <option></option>
                    <option >已下单</option>
                    <option >配送中</option>
                    <option >已完成</option>
                </select>
                -订单号
                <input type="text"  id="orderId"/>
                <button onclick="searchNumOrder(1)">
                    查询
                </button>
            </div>
        </div>

        <c:forEach items="${OrderList}" var="o">

        <div class="mf-menu border-t" style="height: auto; line-height: normal; padding: 30px 0">
            <div class="fl">
                <span class="m-wt1" style="width: 10px"></span>
                <span>${o.orderId}</span>
                <span>${o.userName}</span>
                <span>${o.addTime}</span>
                <span>${o.updateTime}</span>
            </div>
            <div class="fr weiyi">

                <select class="select" id="Type" onchange="updateType(${o.orderId})">
                        <option ${o.orderType==1?"selected":""}>已下单</option>
                        <option ${o.orderType==2?"selected":""}>配送中</option>
                        <option ${o.orderType==3?"selected":""}>已完成</option>

                </select>
                <button class="xiugai" style="padding: 10px"
                        onclick="change('order${o.orderId}',1),getSum(${o.orderId})">
                    详情
                </button>

            </div>

            <div id="update_order${o.orderId}" style="display: none;" class="change">

                <c:forEach items="${o.orderDetails}" var="dt">
                <div class=" clear" style="padding: 20px 0">
                    <span class="m-wt1" style="width: 28px"></span>
                    <span></span>
                    <span class="sp sp-1">${dt.productName}</span>
                    <span class="sp sp-2">${dt.productNum}</span>
                    <span class="sp sp-3" name="money${o.orderId}">${dt.productMoney}</span>
                </div>
                </c:forEach>
                <div class=" clear" style="padding: 20px 0">
                    <span class="m-wt1" style="width: 28px"></span>
                    <span></span>
                    <span class="sp sp-1">总额</span>
                    <span class="sp sp-2"></span>
                    <span class="sp sp-3" id="money${o.orderId}">176.00</span>
                </div>
                <div class=" clear" style="padding: 20px 0">
                    <span class="m-wt1" style="width: 28px"></span>
                    <span></span>
                    <span class="sp sp-4">送餐地址</span>
                    <span>${o.address_details}</span>
                </div>


            </div>
        </div>


        </c:forEach>




        <div class="mf-top" style="margin-top:30px">

            <ul class="pagination fr"
                style="margin-right: 50px; margin-top: 40px">

                <c:forEach var="n" begin="1" end="${OrderTotalPage}">
                    <li><a  href="javascript:"onclick="searchNumOrder(${n})"id="#OrderNowPage">${n}</a></li>
                </c:forEach>
            </ul>
        </div>



    </div>
</div>
</body>
</html>

(8)用户管理模块

package com.bsk.controller;

import com.bsk.bean.User;
import com.bsk.dao.UserDao;
import com.bsk.dao.impl.UserDaoImpl;
import com.bsk.service.UserService;
import com.bsk.service.impl.UserServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/UserServlet")
public class UserServlet extends BaseServlet{
    private  UserService service = new UserServiceImpl();

    //登录
    public void login(HttpServletRequest request, HttpServletResponse response) throws  IOException {
        System.out.println("UserServlet.login");
        String tel = request.getParameter("tel");
        String pwd = request.getParameter("pwd");
        System.out.println(tel+"+"+pwd);

        UserDao dao = new UserDaoImpl();
        User user = dao.selectByTelUser(tel);

        boolean login = service.login(tel, pwd);
        if (login!=true){
            System.out.println("登陆失败");
            response.getWriter().append("0");
        }else {
            //存在用户信息
            //校验该账户是否被停用
            if (user.getUserStatus().equals("Y")!=true){
                System.out.println("账户已被停用");
                response.getWriter().append("2");
            }else {
                if (user.getUserRole().equals("A")!=true){
                    System.out.println("普通用户登陆成功");
                    response.getWriter().append("1");
                    request.getSession().setAttribute("user",user);
                }else {
                    System.out.println("管理员用户");
                    response.getWriter().append("3");
                    request.getSession().setAttribute("user",user);
                }
            }
        }
    }

    //注册
    public void register(HttpServletRequest request, HttpServletResponse response) throws  IOException {
        System.out.println("UserServlet.register");
        String tel = request.getParameter("tel");
        String pwd = request.getParameter("pwd");
        String username = request.getParameter("username");
        String sex = request.getParameter("userSex");
        System.out.println(tel+"+"+pwd+"+"+username+"+"+sex);

        User user = new User();
        user.setUserTel(tel);
        user.setUserPwd(pwd);
        user.setUserName(username);
        user.setUserSex(sex);
        boolean register = service.register(user);
        if (register!=true){
            System.out.println("注册失败");
            response.getWriter().append("0");
        }else {
            System.out.println("注册成功");
            response.getWriter().append("1");
            request.getSession().setAttribute("user",user);

        }
    }

    //修改用户名和性别
    public void updateNameSex(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("updateNameSexServlet.updateNameSex");

        String tel = request.getParameter("tel");
        String userName = request.getParameter("userName");
        String userSex = request.getParameter("userSex");
        System.out.println(tel+"+"+userName+"+"+userSex);

        UserDao dao = new UserDaoImpl();
        User user = dao.selectByTelUser(tel);
        System.out.println(user);

        boolean b = service.updateNameSex(tel,userName,userSex);
        System.out.println("b = " + b);
        if (b!=true){
            System.out.println("修改用户名和性别失败");
            response.getWriter().append("0");
        }else {
            System.out.println("修改用户名和性别成功");
            response.getWriter().append("1");
        }

    }

    //修改用户密码
    public void updatePwd(HttpServletRequest request, HttpServletResponse response) throws Exception {
        System.out.println("UserServlet.updatePwd");
        User user = (User) request.getSession().getAttribute("user");
        String tel = user.getUserTel();
        String newUserPwd = request.getParameter("newPwd");
        System.out.println(tel+"+"+newUserPwd);
        System.out.println(request.getSession().getAttribute("code"));
        System.out.println(request.getParameter("code"));
        // 判断验证码
        if(request.getSession().getAttribute("code").equals(request.getParameter("code"))) {
            boolean b = service.updatePwd(tel,newUserPwd);
            System.out.println(b);
            if (b!=true){
                System.out.println("修改密码失败");
                response.getWriter().append("0");
            }else {
                System.out.println("修改密码成功");
                response.getWriter().append("-1");
            }
        } else {
            System.out.println("验证码输入错误");
            response.getWriter().append("2");
        }


    }

    //退出登录
    public void out(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("UserServlet.out");
        request.getSession().removeAttribute("user");
        response.sendRedirect("main.jsp");
    }


    public void StatusUser(HttpServletRequest request, HttpServletResponse response)throws Exception{
        System.out.println("UserServlet.StatusUser");
        String userId = request.getParameter("id");
        String Status = request.getParameter("type");
        System.out.println(userId+"+"+Status);

        boolean b = service.updateStatus(userId,Status);


        System.out.println("b = " + b);
        if (b!=true){
            System.out.println("启停失败");
            response.getWriter().append("0");
        }else {
            System.out.println("启停成功");
            response.getWriter().append("1");

        }
    }

    public void selectByTimeTel(HttpServletRequest request, HttpServletResponse response)throws Exception{
        System.out.println("UserServlet.selectByTimeTel");
        String addtime = request.getParameter("addtime");
        String tel = request.getParameter("tel");
        System.out.println(addtime+"+"+tel);

        List<User> list = service.selectByTimeTel(addtime, tel);
        if (list!=null){//查询到了
            request.getSession().setAttribute("list",list);
            response.getWriter().append("1");
        }else {//未查询到
            response.getWriter().append("0");
        }

    }

    //分页
    public void search(HttpServletRequest request, HttpServletResponse response) throws Exception {
        System.out.println("UserServlet.search");
        // 获取的参数对象化
        String beginTime = request.getParameter("beginTime");
        String endTime = request.getParameter("endTime");
        String userTel = request.getParameter("userTel");
        String page = request.getParameter("page");
        System.out.println("beginTime = " + beginTime);
        System.out.println("endTime = " + endTime);
        System.out.println("userTel = " + userTel);
        System.out.println("page = " + page);
        User u = new User();
        u.setBeginTime(beginTime);
        u.setEndTime(endTime);
        u.setUserTel(userTel);
        System.out.println(u);
        //定义默认页码
        int nowPage = 1;
        if (page!=null){
            nowPage = Integer.parseInt(page);//获取当前页码
        }
        System.out.println("nowPage = " + nowPage);

        //定义每页显示的数据量
        int pageSize = 4;

        //根据搜索条件确认数据量
        int total = service.search(u, 0, 0).size();
        System.out.println("total = " + total);
        //计算出需要的页码数
        int totalPage = total % pageSize == 0 ? total / pageSize : total % pageSize ;
        System.out.println("totalPage = " + totalPage);

        //获取当前页需要展示数据
        List<User> search = service.search(u, nowPage, pageSize);
        for (User user : search) {
            System.out.println(user);
        }
        //存储(搜索条件,当前页码号,总页码数,当前页面需要展示数据)
        request.setAttribute("u", u);
        request.setAttribute("nowPage", nowPage);
        request.setAttribute("totalPage", totalPage);
        request.setAttribute("search", search);

        //跳转
        request.getRequestDispatcher("user_list.jsp").forward(request, response);


    }
    }

登录页面

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="css/css.css" />
    <link rel="stylesheet" type="text/css" href="css/style.css" />
    <title>登录</title>
    <script type="text/javascript"
            src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="layer/layer.js" type="text/javascript"></script>
    <script src="js/main.js" type="text/javascript"></script>

</head>
<body>

<!--login begin-->
<div class="m-login">
    <div class="login-logo"><img src="images/common/logo.png" /></div>
    <div class="login-title border-bot login-redcolor" style="font-weight:normal">账号密码登陆</div>

    <div class="input-box  border-bot"><img src="images/login/icon-phone.png" /><input type="text" id="tel"  placeholder="请输入手机号" onblur="checkTel(this)" class="input-box1"/></div>
    <div class="input-box  border-bot"><img src="images/login/icon-password.png" /><input type="text" id="pwd"  placeholder="密码,长度6-16字符"  class="input-box1" /></div>
    <div class="input-box" style="text-align:left"><a href="register.jsp" class="login-redcolor" style="text-decoration:underline; font-size:18px">快速注册</a></div>
    <div class="input-box "></div>
    <div class="login-me cursor" onclick="sub()"><button  class="cursor" >登陆</button></div>

</div>
<!--login end-->
</body>
<script type="text/javascript">
    //电话号码校验
    function checkTel(t) {
        var tel = $.trim(t.value);
        var telTest = /^1[3|4|5|8][0-9]\d{4,8}$/;
        console.log(tel);

        //过滤首位无效空格
        if (tel != "") {
            if (!telTest.test(tel)) {
                layer.msg('请输入有效的手机号码');
            }else {
            //校验名字是否已经存在
            $.get("${pageContext.request.contextPath}/CheakTelServlet?tel="+tel, function (data) {
                if (data == "0") {
                    layer.msg("手机号不存在");
                }
            });
        }
        }
    }

    //登录
    function sub() {
        var tel = $("#tel").val().trim();
        var pwd = $("#pwd").val().trim();
        console.log(tel+"+"+pwd);
        if (tel==""||pwd==""){
            layer.msg("手机号和密码不能为空");
        }else {
            $.ajax({
                url:"${pageContext.request.contextPath}/UserServlet?method=login",
                data:{
                    "tel":tel,
                    "pwd":pwd
                },
                dataType:"json",
                async:true,
                type:"post",
                success:function (data) {
                    console.log(data);
                    if (data==1){
                        layer.msg("普通用户登陆成功");
                        top.location.reload();
                    }else if (data==0){
                        layer.msg("用户名或密码错误");
                    }else if (data==2){
                        layer.msg("该账户已被停用");
                    }else if (data==3){
                        layer.msg("管理员登陆成功");
                        top.location.reload();
                    }
                }
            })
        }
    }

</script>


</html>

注册页面

<%@ page contentType="text/html;charset=UTF-8" language="java" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="css/css.css" />
    <link rel="stylesheet" type="text/css" href="css/style.css" />
    <title>注册</title>
    <script type="text/javascript"
            src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="layer/layer.js" type="text/javascript"></script>
    <script src="js/main.js" type="text/javascript"></script>
</head>

<body>

<!--register begin-->
<div class="m-login">
    <div class="login-logo"><img src="images/common/logo.png" /></div>
    <div class="login-title border-bot">欢迎注册加入会员中心</div>
    <div class="input-box  border-bot"><img src="images/login/icon-phone.png" /><input id="tel" type="text" placeholder="请输入手机号" onblur="checkTel(this)" class="input-box1"/></div>
    <div class="input-box  border-bot"><img src="images/login/icon-password.png" /><input id="pwd" type="text" placeholder="密码,长度6-16字符"  class="input-box1" /></div>
    <div class="input-box  border-bot"><img src="images/login/icon-name.png" /><input id="username" type="text" placeholder="姓名,最多5个字" />
        <span ><a href="#"
                  id="M" onclick="setSex(this)" class="login-redcolor">先生</a> | <a
                href="#" id="F" onclick="setSex(this)" style="margin: 0">女士</a></span></div>
    <div class="input-box "></div>
    <div class="login-me cursor" onclick="register()"><button  class="cursor" >立即注册</button></div>
</div>
<!--register end-->
</body>
<script>
    //选中的性别
    var userSex="M";
    //性别切换
    function setSex(t){
        userSex = t.id;
        if(t.id == "M"){
            $("#F").removeClass("login-redcolor");
            $("#M").addClass("login-redcolor");
        }else{
            $("#M").removeClass("login-redcolor");
            $("#F").addClass("login-redcolor");
        }
    }

    //电话号码校验
    function checkTel(t) {
        var tel = $.trim(t.value);
        var telTest = /^1[3|4|5|8][0-9]\d{4,8}$/;
        console.log(tel);
        //过滤首位无效空格
        if (tel != "") {
            if (!telTest.test(tel)) {
                layer.msg('请输入有效的手机号码');
            }else {
                //校验名字是否已经存在
                $.get("${pageContext.request.contextPath}/CheakTelServlet?tel="+tel, function (data) {
                    if (data == "1") {
                        layer.msg("手机号已注册");
                    }
                });
            }
        }
    }

    //注册
    function register() {
        var tel = $("#tel").val().trim();
        var pwd = $("#pwd").val().trim();
        var username = $("#username").val().trim();
        console.log(tel + "+" + pwd+"+"+username+"");
        if (tel == "" || pwd == "" || username == "") {
            layer.msg("手机号、密码和用户名不能为空");
        } else if (pwd.length < 6 || pwd.length > 20){
            layer.msg('请输入6~20位密码');
        } else if (username.length < 2 || username.length > 10){
            layer.msg('请输入2~10位用户名');
        }else {
                $.ajax({
                    url: "${pageContext.request.contextPath}/UserServlet?method=register",
                    data: {
                        "tel": tel,
                        "pwd": pwd,
                        "username": username,
                        "userSex":userSex
                    },
                    dataType: "json",
                    async: true,
                    type: "post",
                    success: function (data) {
                        console.log(data);
                        if (data == 1) {
                            layer.msg("注册成功");
                            top.location.reload();
                        } else {
                            layer.msg("注册失败");
                        }
                    }
                })
            }
    }


</script>
</html>

账号管理页面 

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="css/css.css" />
    <link rel="stylesheet" type="text/css" href="css/style.css" />
    <link rel="stylesheet" type="text/css" href="css/menu.css" />
    <title>用户管理</title>
    <script type="text/javascript"
            src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="layer/layer.js" type="text/javascript"></script>
    <script src="js/main.js" type="text/javascript"></script>
    <script type="text/javascript">
        function update(id, type) {
            console.log(id+"+"+type);
            var msg;
            if (type == 'Y') {
                msg = "启用"
            } else {
                msg = "停用"
            }
            layer.confirm('确定要' + msg + '吗?', {
                btn : [ '确定', '取消' ]
                //按钮
            }, function() {
                layer.msg(msg + '成功');
                $.ajax({
                    url: "${pageContext.request.contextPath}/UserServlet?method=StatusUser",
                    data: {
                        "id":id,
                        "type":type
                    },
                    dataType: "json",
                    async: true,
                    type: "post",
                    success: function (data) {
                        if (data == 1) {
                            layer.msg('启停成功');
                            location.href="${pageContext.request.contextPath}/UserServlet?method=search";
                        } else {
                            layer.msg("启停失败");
                        }
                    }
                })
            });
        }


function searchNum(i) {
// $("#pageNum"+i).val().trim();
    location.href="${pageContext.request.contextPath}/UserServlet?method=search&page="+i
    +"&beginTime="+$("#beginTime").val().trim()+"&endTime="+$("#endTime").val().trim()
    +"&userTel="+$("#userTel").val().trim();
}

    </script>
</head>
<body>
<div class="m-main">
    <div class="m-food">
        <div class="mf-top border-t">
            <div class="fl">用户管理</div>
            <div class="fr">
                <input type="date" id="beginTime"/>
                -
                <input type="date" id="endTime" />
                -
                <input type="text" id="userTel" placeholder="手机号码" />
                <button onclick="searchNum(1)">查询</button>
            </div>
        </div>
        <c:forEach items="${search}" var="user">
        <div class="mf-menu border-t">

                            <div class="fl">
                                <span class="m-wt1"></span>
                                <span>${user.userTel}</span>
                                <span>${user.userName}</span>
                                <span>${user.userSex == "M"?"男":"女"}</span>
                                <span>${user.addTime}</span>
                        </div>

        <div class="fr">
            <button class="${user.userStatus == "Y"?"xiugai":"xiajia"}" onclick="update(${user.userId},'${user.userStatus == "Y"?"N":"Y"}')">${user.userStatus == "Y"?"停用":"启用"}</button>
        </div>
    </div>
        </c:forEach>





        <div class="mf-top" style="margin-top:30px">

            <ul class="pagination" style="margin-left:250px">
                <c:forEach var="i" begin="1" end="${requestScope.totalPage}">
                <li><a  href="javascript:"onclick="searchNum(${i})"id="#pageNum">${i}</a></li>
                </c:forEach>
            </ul>
        </div>

    </div>
</div>
</body>
</html>

标签:JavaWeb,request,System,response,println,订餐,必胜客,id,out
来源: https://blog.csdn.net/Zyw907155124/article/details/121038411