——————————DescriptionStart——————————
运行环境 Java≥8、MySQL≥5.7、Tomcat≥8
开发工具 eclipse/idea/myeclipse/sts等均可配置运行
适用 课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb的JSP+Servlet自行车商城系统(java+jsp+bootstrap+servlet+mysql)
项目介绍
本项目分为前后台,分为管理员与普通用户两种角色,管理员登录后台,普通用户登录前台;
用户角色包含以下功能:
用户登录,修改个人信息,查看首页,查看商品详情,加入购物车,提交订单,查看我的订单等功能。
管理员角色包含以下功能:
管理员登录,订单管理,客户信息管理,二手自行车管理,类目管理等功能。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.数据库:MySql 5.7版本; 6.是否Maven项目:否;
技术栈
JSP+CSS+jQuery+bootstrap+mysql+servlet
使用说明
使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中src/utils/DBUtil.java配置文件中的数据库配置改为自己的配置; 4. 运行项目,输入localhost:8080/jsp_ershou_zxc/ 登录 注:tomcat中配置项目路径必须为jsp_ershou_zxc,否则会有异常; 用户账号/密码:user/123456 管理员账号/密码:admin/admin
——————————CodeStart——————————
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 @WebListener() public class ApplicationListener implements ServletContextListener , HttpSessionListener , HttpSessionAttributeListener { TypeService tsService=new TypeService(); public ApplicationListener () { } public void contextInitialized (ServletContextEvent sce) { sce.getServletContext().setAttribute("typeList" ,tsService.GetAllType()); } public void contextDestroyed (ServletContextEvent sce) { } public void sessionCreated (HttpSessionEvent se) { }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 @WebServlet(name = "user_changeaddress",urlPatterns = "/user_changeaddress") public class UserChangeAddressServlet extends HttpServlet { private UserService uService = new UserService(); protected void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { User loginUser = (User) request.getSession().getAttribute("user" ); try { BeanUtils.copyProperties(loginUser, request.getParameterMap()); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } uService.updateUserAddress(loginUser); request.setAttribute("msg" , "收件信息更新成功!" ); request.getRequestDispatcher("/user_center.jsp" ).forward(request, response); } protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 @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); } } protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 @WebServlet(name = "admin_user_add",urlPatterns = "/admin/user_add") public class AdminUserAddServlet 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) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } if (uService.register(user)) { request.setAttribute("msg" , "客户添加成功!" ); request.getRequestDispatcher("/admin/user_list" ).forward(request, response); }else { request.setAttribute("failMsg" , "用户名或邮箱重复,请重新填写!" ); request.setAttribute("u" ,user); request.getRequestDispatcher("/admin/user_add.jsp" ).forward(request, response); } } } @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 {
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 } in.close(); out.close(); 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) { e.printStackTrace(); } } protected void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 g.setImage2("/picture" +fileName); } } } gService.insert(g); request.getRequestDispatcher("/admin/goods_list" ).forward(request, response); } catch (FileUploadException e) { e.printStackTrace(); } } protected void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } } @WebListener() public class ApplicationListener implements ServletContextListener , HttpSessionListener , HttpSessionAttributeListener { TypeService tsService=new TypeService(); public ApplicationListener () { } public void contextInitialized (ServletContextEvent sce) {
——————————PayStart——————————
项目链接: https://javayms.github.io?id=491122512008200nf https://javayms.pages.dev?id=491122512008200nf