文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

基于javaweb+mysql的jsp+servlet在线蛋糕商城系统(java+jsp+jdbc+mysql)

2023-12-23 19:28

关注

基于javaweb+mysql的jsp+servlet在线蛋糕商城系统(java+jsp+jdbc+mysql)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

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

适用

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

功能说明

基于javaweb+mysql的JSP+Servlet在线蛋糕商城系统(java+jsp+jdbc+mysql)

一、项目简述

功能: 主页显示热销商品;所有蛋糕商品展示,可进行商品搜 索;点击商品进入商品详情页,具有立即购买和加入购物 车功能,可增减购买商品数量亦可手动输入(同时验证库 存),热销商品展示。立即购买进入确认订单页面,可选择 已经添加的地址,亦可新增地址。(同时验证库存),可选 择购买哪些商品,可删除不需要的商品。点击结算进入确 认订单页面,确认后提交订单。后台管理:(修改密码 等),商品管理(商品批量添加、上下架等),订单管理。

二、项目运行

环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe ( IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)

项目技术: JSP + C3P0+ Servlert + html+ css + JavaScript + JQuery + Ajax + Fileupload

        }        Type t=null;        if(id!=0)        {            t=tService.selectTypeNameByID(id);        }        request.setAttribute("t",t);        //List list=gService.selectGoodsByTypeID(id,1,8);        //request.setAttribute("goodsList",list);        if(pageNumber<=0)            pageNumber=1;        Page p=gService.selectPageByTypeID(id,pageNumber);        if(p.getTotalPage()==0)        {            p.setTotalPage(1);            p.setPageNumber(1);        }        else {            if(pageNumber>=p.getTotalPage()+1)            {                p=gService.selectPageByTypeID(id,p.getTotalPage());            }        }        request.setAttribute("p",p);        request.setAttribute("id",String.valueOf(id));        request.getRequestDispatcher("/goods_list.jsp").forward(request,response);    }}package com.demo.servlet;@WebServlet(name = "admin_goods_list",urlPatterns = "/admin/goods_list")public class AdminGoodsListServlet extends HttpServlet {    private GoodsService gService = new GoodsService();        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        int type = 0;//推荐类型        if(request.getParameter("type") != null) {
    }    private GoodsService gService = new GoodsService();    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        String keyword = request.getParameter("keyword");        int pageNumber = 1;        if(request.getParameter("pageNumber") != null) {            try {                pageNumber=Integer.parseInt(request.getParameter("pageNumber") ) ;            }            catch (Exception e)            {            }        }        if(pageNumber<=0)        {            pageNumber=1;        }        Page p =gService.getSearchGoodsPage(keyword,pageNumber);        if(p.getTotalPage()==0)        {            p.setTotalPage(1);            p.setPageNumber(1);        }        else {            if(pageNumber>=p.getTotalPage()+1)            {                p =gService.getSearchGoodsPage(keyword,pageNumber);            }        }        request.setAttribute("p", p);        request.setAttribute("keyword", URLEncoder.encode(keyword,"utf-8"));        request.getRequestDispatcher("/goods_search.jsp").forward(request, response);    }}package com.demo.servlet;
        }    }        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        // TODO Auto-generated method stub        doGet(request, response);    }}package com.demo.servlet;@WebServlet(name = "admin_goods_add",urlPatterns = "/admin/goods_add")public class AdminGoodsAddServlet extends HttpServlet {    private GoodsService gService = new GoodsService();        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        DiskFileItemFactory factory=new DiskFileItemFactory();        ServletFileUpload upload = new ServletFileUpload(factory);        try {            List<FileItem> list = upload.parseRequest(request);            Goods g = new Goods();            for(FileItem item:list) {                if(item.isFormField()) {                    String fieldName = item.getFieldName();                    if("name".equals(fieldName)){                        g.setName(item.getString("utf-8"));                    }else if("price".equals(fieldName)){                        g.setPrice(Integer.parseInt(item.getString("utf-8")));
@WebServlet(name = "user_register",urlPatterns = "/user_rigister")public class UserRegisterServlet extends HttpServlet {    private UserService uService = new UserService();    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        User user = new User();        try {            BeanUtils.copyProperties(user, request.getParameterMap());        } catch (IllegalAccessException e) {            // TODO Auto-generated catch block            e.printStackTrace();        } catch (InvocationTargetException e) {            // TODO Auto-generated catch block            e.printStackTrace();        }        if(uService.register(user)) {            request.setAttribute("msg", "注册成功,请登录!");            request.getRequestDispatcher("user_login.jsp").forward(request, response);        }else {            request.setAttribute("msg", "用户名或邮箱重复,请重新填写!");            request.getRequestDispatcher("user_register.jsp").forward(request, response);        }    }    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {    }}package com.demo.servlet;
        request.setAttribute("p", p);        request.getRequestDispatcher("/admin/order_list.jsp").forward(request, response);    }}package com.demo.servlet;@WebServlet(name = "goods_search",urlPatterns = "/goods_search")public class GoodsSearchServlet extends HttpServlet {    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {    }    private GoodsService gService = new GoodsService();    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        String keyword = request.getParameter("keyword");        int pageNumber = 1;        if(request.getParameter("pageNumber") != null) {            try {                pageNumber=Integer.parseInt(request.getParameter("pageNumber") ) ;            }            catch (Exception e)            {            }        }        if(pageNumber<=0)        {            pageNumber=1;        }        Page p =gService.getSearchGoodsPage(keyword,pageNumber);        if(p.getTotalPage()==0)
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)     */    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        int id = Integer.parseInt(request.getParameter("id"));        boolean isSuccess = uService.delete(id);        if(isSuccess) {            request.setAttribute("msg", "客户删除成功");        }else {            request.setAttribute("failMsg", "客户有下的订单,请先删除该客户下的订单,再来删除客户!");        }        request.getRequestDispatcher("/admin/user_list").forward(request, response);    }        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        // TODO Auto-generated method stub        doGet(request, response);    }}package com.demo.servlet;@WebServlet(name = "user_changepwd",urlPatterns = "/user_changepwd")public class UserChangePwd extends HttpServlet {    private UserService uService = new UserService();    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        String password = request.getParameter("password");        String newPwd = request.getParameter("newPassword");        User u = (User) request.getSession().getAttribute("user");
public class GoodsListServlet extends HttpServlet {    private GoodsService gService=new GoodsService();    private TypeService tService=new TypeService();    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {    }    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        int id=0;        if(request.getParameter("typeid")!=null)        {            id=Integer.parseInt(request.getParameter("typeid"));        }        int pageNumber=1;        if(request.getParameter("pageNumber")!=null) {            try {                pageNumber=Integer.parseInt(request.getParameter("pageNumber"));            }            catch (Exception e)            {            }        }        Type t=null;        if(id!=0)        {            t=tService.selectTypeNameByID(id);        }        request.setAttribute("t",t);        //List list=gService.selectGoodsByTypeID(id,1,8);        //request.setAttribute("goodsList",list);        if(pageNumber<=0)            pageNumber=1;        Page p=gService.selectPageByTypeID(id,pageNumber);        if(p.getTotalPage()==0)        {            p.setTotalPage(1);            p.setPageNumber(1);        }        else {            if(pageNumber>=p.getTotalPage()+1)            {                p=gService.selectPageByTypeID(id,p.getTotalPage());            }
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)     */    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        int type = 0;//推荐类型        if(request.getParameter("type") != null) {            type=Integer.parseInt(request.getParameter("type") ) ;        }        int pageNumber = 1;        if(request.getParameter("pageNumber") != null) {            try {                pageNumber=Integer.parseInt(request.getParameter("pageNumber") ) ;            }            catch (Exception e)            {            }        }        if(pageNumber<=0)            pageNumber=1;        Page p = gService.getGoodsRecommendPage(type, pageNumber);        if(p.getTotalPage()==0)        {            p.setTotalPage(1);            p.setPageNumber(1);        }        else {            if(pageNumber>=p.getTotalPage()+1)            {                p = gService.getGoodsRecommendPage(type, pageNumber);            }        }        request.setAttribute("p", p);        request.setAttribute("type", type);        request.getRequestDispatcher("/admin/goods_list.jsp").forward(request, response);    }        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        // TODO Auto-generated method stub        doGet(request, response);    }}package com.demo.servlet;
public class GoodsListServlet extends HttpServlet {    private GoodsService gService=new GoodsService();    private TypeService tService=new TypeService();    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {    }    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        int id=0;        if(request.getParameter("typeid")!=null)        {            id=Integer.parseInt(request.getParameter("typeid"));        }        int pageNumber=1;        if(request.getParameter("pageNumber")!=null) {            try {                pageNumber=Integer.parseInt(request.getParameter("pageNumber"));            }            catch (Exception e)            {            }        }        Type t=null;        if(id!=0)        {            t=tService.selectTypeNameByID(id);        }        request.setAttribute("t",t);        //List list=gService.selectGoodsByTypeID(id,1,8);        //request.setAttribute("goodsList",list);        if(pageNumber<=0)            pageNumber=1;        Page p=gService.selectPageByTypeID(id,pageNumber);        if(p.getTotalPage()==0)        {            p.setTotalPage(1);            p.setPageNumber(1);        }        else {            if(pageNumber>=p.getTotalPage()+1)
        String ue = request.getParameter("ue");        String password = request.getParameter("password");        User user = uService.login(ue, password);        if(user==null) {            request.setAttribute("failMsg", "用户名、邮箱或者密码错误,请重新登录!");            request.getRequestDispatcher("/user_login.jsp").forward(request, response);        }else {            request.getSession().setAttribute("user", user);            if(user.isIsadmin()) {            request.getRequestDispatcher("/admin/index.jsp").forward(request, response);            }else {                response.sendRedirect("/");            }        }    }    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {    }}package com.demo.servlet;@WebServlet(name = "admin_type_edit",urlPatterns = "/admin/type_edit")public class AdminTypeEditServlet extends HttpServlet {    private TypeService tService = new TypeService();        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        Type t = new Type();        try {            BeanUtils.copyProperties(t, request.getParameterMap());        } catch (Exception e) {            // TODO Auto-generated catch block            e.printStackTrace();        }
@WebServlet(name = "order_confirm",urlPatterns = "/order_confirm")public class OrderConfirmServlet extends HttpServlet {    private OrderService oService = new OrderService();    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        Order o = (Order) request.getSession().getAttribute("order");        try {            BeanUtils.copyProperties(o, request.getParameterMap());        } catch (IllegalAccessException e) {            // TODO Auto-generated catch block            e.printStackTrace();        } catch (InvocationTargetException e) {            // TODO Auto-generated catch block            e.printStackTrace();        }        o.setDatetime(new Date());        o.setStatus(2);        o.setUser((User) request.getSession().getAttribute("user"));        oService.addOrder(o);        request.getSession().removeAttribute("order");        request.setAttribute("msg", "订单支付成功!");        request.getRequestDispatcher("/order_success.jsp").forward(request, response);    }    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {    }}package com.demo.servlet;
@WebServlet(name = "admin_goods_add",urlPatterns = "/admin/goods_add")public class AdminGoodsAddServlet extends HttpServlet {    private GoodsService gService = new GoodsService();        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        DiskFileItemFactory factory=new DiskFileItemFactory();        ServletFileUpload upload = new ServletFileUpload(factory);        try {            List<FileItem> list = upload.parseRequest(request);            Goods g = new Goods();            for(FileItem item:list) {                if(item.isFormField()) {                    String fieldName = item.getFieldName();                    if("name".equals(fieldName)){                        g.setName(item.getString("utf-8"));                    }else if("price".equals(fieldName)){                        g.setPrice(Integer.parseInt(item.getString("utf-8")));                    }else if("intro".equals(fieldName)){                        g.setIntro(item.getString("utf-8"));                    }else if("stock".equals(fieldName)){                        g.setStock(Integer.parseInt(item.getString("utf-8")));                    }else if("typeid".equals(fieldName)){                        g.setTypeid(Integer.parseInt(item.getString("utf-8")));
            e.printStackTrace();        }        if(uService.register(user)) {            request.setAttribute("msg", "注册成功,请登录!");            request.getRequestDispatcher("user_login.jsp").forward(request, response);        }else {            request.setAttribute("msg", "用户名或邮箱重复,请重新填写!");            request.getRequestDispatcher("user_register.jsp").forward(request, response);        }    }    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {    }}package com.demo.servlet;@WebServlet(name = "admin_user_list",urlPatterns = "/admin/user_list")public class AdminUserListServlet extends HttpServlet {    private UserService uService = new UserService();        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        int pageNumber = 1;        if(request.getParameter("pageNumber") != null) {            try {                pageNumber=Integer.parseInt(request.getParameter("pageNumber") ) ;            }            catch (Exception e)            {            }        }        if(pageNumber<=0)            pageNumber=1;        Page p = uService.getUserPage(pageNumber);        if(p.getTotalPage()==0)        {            p.setTotalPage(1);            p.setPageNumber(1);
@WebServlet(name = "goodrecommendList",urlPatterns = "/goodsrecommend_list")public class GoodRecommendListServlet extends HttpServlet {    private GoodsService gService = new GoodsService();    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        int type = Integer.parseInt(request.getParameter("type") ) ;        int pageNumber = 1;        if(request.getParameter("pageNumber") != null) {            try {                pageNumber=Integer.parseInt(request.getParameter("pageNumber") ) ;            }            catch (Exception e)            {            }        }        if(pageNumber<=0)            pageNumber=1;        Page p = gService.getGoodsRecommendPage(type, pageNumber);        if(p.getTotalPage()==0)        {            p.setTotalPage(1);            p.setPageNumber(1);        }        else {            if(pageNumber>=p.getTotalPage()+1)            {                p = gService.getGoodsRecommendPage(type, p.getTotalPage());            }        }        request.setAttribute("p", p);        request.setAttribute("t", type);        request.getRequestDispatcher("goodsrecommend_list.jsp").forward(request, response);    }}package com.demo.servlet;
        int id=0;        if(request.getParameter("typeid")!=null)        {            id=Integer.parseInt(request.getParameter("typeid"));        }        int pageNumber=1;        if(request.getParameter("pageNumber")!=null) {            try {                pageNumber=Integer.parseInt(request.getParameter("pageNumber"));            }            catch (Exception e)            {            }        }        Type t=null;        if(id!=0)        {            t=tService.selectTypeNameByID(id);        }        request.setAttribute("t",t);        //List list=gService.selectGoodsByTypeID(id,1,8);        //request.setAttribute("goodsList",list);        if(pageNumber<=0)            pageNumber=1;        Page p=gService.selectPageByTypeID(id,pageNumber);        if(p.getTotalPage()==0)        {            p.setTotalPage(1);            p.setPageNumber(1);        }        else {            if(pageNumber>=p.getTotalPage()+1)            {                p=gService.selectPageByTypeID(id,p.getTotalPage());            }        }        request.setAttribute("p",p);
        boolean isSuccess = uService.delete(id);        if(isSuccess) {            request.setAttribute("msg", "客户删除成功");        }else {            request.setAttribute("failMsg", "客户有下的订单,请先删除该客户下的订单,再来删除客户!");        }        request.getRequestDispatcher("/admin/user_list").forward(request, response);    }        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        // TODO Auto-generated method stub        doGet(request, response);    }}package com.demo.servlet;@WebServlet(name = "user_changepwd",urlPatterns = "/user_changepwd")public class UserChangePwd extends HttpServlet {    private UserService uService = new UserService();    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        String password = request.getParameter("password");        String newPwd = request.getParameter("newPassword");        User u = (User) request.getSession().getAttribute("user");        if(password.equals(u.getPassword())) {            u.setPassword(newPwd);            uService.updatePwd(u);            request.setAttribute("msg", "修改成功!");            request.getRequestDispatcher("/user_center.jsp").forward(request, response);        }else {            request.setAttribute("failMsg", "修改失败,原密码不正确,你再想想!");            request.getRequestDispatcher("/user_center.jsp").forward(request, response);        }
@WebListener()public class ApplicationListener implements ServletContextListener,        HttpSessionListener, HttpSessionAttributeListener {    TypeService tsService=new TypeService();    // Public constructor is required by com.demo.servlet spec    public ApplicationListener() {    }    // -------------------------------------------------------    // ServletContextListener implementation    // -------------------------------------------------------    public void contextInitialized(ServletContextEvent sce) {              sce.getServletContext().setAttribute("typeList",tsService.GetAllType());    }    public void contextDestroyed(ServletContextEvent sce) {          }    // -------------------------------------------------------    // HttpSessionListener implementation    // -------------------------------------------------------    public void sessionCreated(HttpSessionEvent se) {            }    public void sessionDestroyed(HttpSessionEvent se) {            }    // -------------------------------------------------------    // HttpSessionAttributeListener implementation
    // -------------------------------------------------------    // ServletContextListener implementation    // -------------------------------------------------------    public void contextInitialized(ServletContextEvent sce) {              sce.getServletContext().setAttribute("typeList",tsService.GetAllType());    }    public void contextDestroyed(ServletContextEvent sce) {          }    // -------------------------------------------------------    // HttpSessionListener implementation    // -------------------------------------------------------    public void sessionCreated(HttpSessionEvent se) {            }    public void sessionDestroyed(HttpSessionEvent se) {            }    // -------------------------------------------------------    // HttpSessionAttributeListener implementation    // -------------------------------------------------------    public void attributeAdded(HttpSessionBindingEvent sbe) {          }
                    while( (len=in.read(buffer))>0 ) {                        out.write(buffer);                    }                    in.close();                    out.close();                    //item.delete();                    String fieldName = item.getFieldName();                    if("cover".equals(fieldName)){                        g.setCover("/picture"+fileName);                    } else  if("image1".equals(fieldName)){                        g.setImage1("/picture"+fileName);                    } else  if("image2".equals(fieldName)){                        g.setImage2("/picture"+fileName);                    }                }            }            gService.update(g);            request.getRequestDispatcher("/admin/goods_list?pageNumber="+pageNumber+"&type="+type).forward(request, response);        } catch (FileUploadException e) {            // TODO Auto-generated catch block            e.printStackTrace();        }    }        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        // TODO Auto-generated method stub        doGet(request, response);    }}package com.demo.servlet;
    public void attributeReplaced(HttpSessionBindingEvent sbe) {          }}package com.demo.servlet;@WebServlet(name = "goods_List",urlPatterns = "/goods_list")public class GoodsListServlet extends HttpServlet {    private GoodsService gService=new GoodsService();    private TypeService tService=new TypeService();    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {    }    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        int id=0;        if(request.getParameter("typeid")!=null)        {            id=Integer.parseInt(request.getParameter("typeid"));        }        int pageNumber=1;        if(request.getParameter("pageNumber")!=null) {            try {                pageNumber=Integer.parseInt(request.getParameter("pageNumber"));            }            catch (Exception e)
        int id=0;        if(request.getParameter("typeid")!=null)        {            id=Integer.parseInt(request.getParameter("typeid"));        }        int pageNumber=1;        if(request.getParameter("pageNumber")!=null) {            try {                pageNumber=Integer.parseInt(request.getParameter("pageNumber"));            }            catch (Exception e)            {            }        }        Type t=null;        if(id!=0)        {            t=tService.selectTypeNameByID(id);        }        request.setAttribute("t",t);        //List list=gService.selectGoodsByTypeID(id,1,8);        //request.setAttribute("goodsList",list);        if(pageNumber<=0)            pageNumber=1;        Page p=gService.selectPageByTypeID(id,pageNumber);        if(p.getTotalPage()==0)        {            p.setTotalPage(1);            p.setPageNumber(1);        }        else {            if(pageNumber>=p.getTotalPage()+1)            {                p=gService.selectPageByTypeID(id,p.getTotalPage());            }        }        request.setAttribute("p",p);        request.setAttribute("id",String.valueOf(id));        request.getRequestDispatcher("/goods_list.jsp").forward(request,response);    }}package com.demo.servlet;
            p.setPageNumber(1);        }        else {            if(pageNumber>=p.getTotalPage()+1)            {                p =gService.getSearchGoodsPage(keyword,pageNumber);            }        }        request.setAttribute("p", p);        request.setAttribute("keyword", URLEncoder.encode(keyword,"utf-8"));        request.getRequestDispatcher("/goods_search.jsp").forward(request, response);    }}package com.demo.servlet;@WebServlet(name = "order_confirm",urlPatterns = "/order_confirm")public class OrderConfirmServlet extends HttpServlet {    private OrderService oService = new OrderService();    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        Order o = (Order) request.getSession().getAttribute("order");        try {            BeanUtils.copyProperties(o, request.getParameterMap());        } catch (IllegalAccessException e) {            // TODO Auto-generated catch block            e.printStackTrace();        } catch (InvocationTargetException e) {            // TODO Auto-generated catch block            e.printStackTrace();        }        o.setDatetime(new Date());        o.setStatus(2);        o.setUser((User) request.getSession().getAttribute("user"));        oService.addOrder(o);        request.getSession().removeAttribute("order");
                    }else if("stock".equals(fieldName)){                        g.setStock(Integer.parseInt(item.getString("utf-8")));                    }else if("typeid".equals(fieldName)){                        g.setTypeid(Integer.parseInt(item.getString("utf-8")));                    }                }else {                    if(item.getInputStream().available()<=0)continue;                    String fileName = item.getName();                    fileName = fileName.substring(fileName.lastIndexOf("."));                    fileName = "/"+new Date().getTime()+fileName;                    String path = this.getServletContext().getRealPath("/picture")+fileName;                    InputStream in = item.getInputStream();                    FileOutputStream out = new FileOutputStream(path);                    byte[] buffer = new byte[1024];                    int len=0;                    while( (len=in.read(buffer))>0 ) {                        out.write(buffer);                    }                    in.close();                    out.close();                    //item.delete();                    String fieldName = item.getFieldName();                    if("cover".equals(fieldName)){                        g.setCover("/picture"+fileName);                    } else  if("image1".equals(fieldName)){                        g.setImage1("/picture"+fileName);                    } else  if("image2".equals(fieldName)){                        g.setImage2("/picture"+fileName);                    }                }            }            gService.insert(g);            request.getRequestDispatcher("/admin/goods_list").forward(request, response);        } catch (FileUploadException e) {            // TODO Auto-generated catch block            e.printStackTrace();        }    }        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        // TODO Auto-generated method stub        doGet(request, response);    }}package com.demo.common.listener;
        request.getSession().removeAttribute("order");        request.setAttribute("msg", "订单支付成功!");        request.getRequestDispatcher("/order_success.jsp").forward(request, response);    }    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {    }}package com.demo.servlet;@WebServlet(name = "user_register",urlPatterns = "/user_rigister")public class UserRegisterServlet extends HttpServlet {    private UserService uService = new UserService();    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        User user = new User();        try {            BeanUtils.copyProperties(user, request.getParameterMap());        } catch (IllegalAccessException e) {            // TODO Auto-generated catch block            e.printStackTrace();        } catch (InvocationTargetException e) {            // TODO Auto-generated catch block            e.printStackTrace();        }        if(uService.register(user)) {            request.setAttribute("msg", "注册成功,请登录!");            request.getRequestDispatcher("user_login.jsp").forward(request, response);        }else {            request.setAttribute("msg", "用户名或邮箱重复,请重新填写!");
      */    }    public void attributeReplaced(HttpSessionBindingEvent sbe) {          }}package com.demo.servlet;@WebServlet(name = "goods_List",urlPatterns = "/goods_list")public class GoodsListServlet extends HttpServlet {    private GoodsService gService=new GoodsService();    private TypeService tService=new TypeService();    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {    }    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        int id=0;        if(request.getParameter("typeid")!=null)        {            id=Integer.parseInt(request.getParameter("typeid"));        }        int pageNumber=1;        if(request.getParameter("pageNumber")!=null) {            try {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {    }}package com.demo.servlet;@WebServlet(name = "user_login",urlPatterns = "/user_login")public class UserLoginServlet extends HttpServlet {    private UserService uService = new UserService();    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        String ue = request.getParameter("ue");        String password = request.getParameter("password");        User user = uService.login(ue, password);        if(user==null) {            request.setAttribute("failMsg", "用户名、邮箱或者密码错误,请重新登录!");            request.getRequestDispatcher("/user_login.jsp").forward(request, response);        }else {            request.getSession().setAttribute("user", user);            if(user.isIsadmin()) {            request.getRequestDispatcher("/admin/index.jsp").forward(request, response);            }else {                response.sendRedirect("/");            }        }    }    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {    }}package com.demo.servlet;
@WebServlet(name = "admin_goods_recommend",urlPatterns = "/admin/goods_recommend")public class AdminGoodsRecommendServlet extends HttpServlet {    private GoodsService gService = new GoodsService();        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        int id = Integer.parseInt(request.getParameter("id"));        String method = request.getParameter("method");        int typeTarget=Integer.parseInt(request.getParameter("typeTarget"));        if(method.equals("add")) {            gService.addRecommend(id, typeTarget);        }else {            gService.removeRecommend(id, typeTarget);        }        request.getRequestDispatcher("/admin/goods_list").forward(request, response);    }        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        // TODO Auto-generated method stub        doGet(request, response);    }}package com.demo.servlet;@WebServlet(name = "admin_user_delete",urlPatterns = "/admin/user_delete")

请添加图片描述

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

来源地址:https://blog.csdn.net/m0_71414463/article/details/131859124

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-数据库
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯