——————————DescriptionStart——————————
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明







基于javaweb的JSP+Servlet网吧管理系统(java+jsp+servlet+mysql+jdbc)
管理员
admin 123456
普通用户
小张 123456
二狗 123456
——————————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 35 36 37 38 39 40 41 42 43 44 45 46 47
| String pageNum = request.getParameter("pageNum"); com.demo.util.PageBean<Object> pb = new com.demo.util.PageBean(Integer.valueOf(pageNum != null ? pageNum : "1"), totalRecord); params.put("startIndex", pb.getStartIndex()); params.put("pageSize", pb.getPageSize()); List list = (List) noticeService.list(params).get("list"); pb.setServlet("NoticeServlet"); pb.setSearchColumn(searchColumn); pb.setKeyword(keyword); pb.setList(list); request.getSession().setAttribute("pageBean", pb); request.getSession().setAttribute("list", pb.getList());
response.sendRedirect("notice_list.jsp"); } }
public class LoginFilter implements Filter {
public void destroy() { }
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; HttpSession session = request.getSession(); request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); session.removeAttribute("alert_msg"); String uri = request.getRequestURI(); String action = request.getParameter("action"); if (uri.endsWith("login.jsp") || uri.endsWith("register.jsp") || "register".equalsIgnoreCase(action) || "validationCode".equalsIgnoreCase(action) || "login".equalsIgnoreCase(action) || uri.endsWith(".css") || uri.endsWith(".js") || uri.endsWith(".png") || uri.endsWith(".jpg")) { chain.doFilter(request, response); return; } else if (session.getAttribute("loginUser") == null) { session.setAttribute("alert_msg", "错误:请先登录!"); response.sendRedirect("login.jsp"); return;
|
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 41 42 43 44 45
| String newPassword = request.getParameter("newPassword"); loginUser.setPassword(newPassword); UserService userService = new UserServiceImpl(); userService.update(loginUser); msg = "修改成功!"; } request.getSession().setAttribute("alert_msg", msg); request.getRequestDispatcher("reset_password.jsp").forward(request, response); } else { response.sendRedirect("login.jsp"); } }
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); }
private Color getRandomColor(int minColor, int maxColor) { Random random = new Random(); if (minColor > 255) minColor = 255; if (maxColor > 255) maxColor = 255; int red = minColor + random.nextInt(maxColor - minColor); int green = minColor + random.nextInt(maxColor - minColor); int blue = minColor + random.nextInt(maxColor - minColor); return new Color(red, green, blue); } }
|
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 41 42 43 44 45
| * * @param request * @param response * @throws ServletException * @throws IOException */ @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); }
private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException { String searchColumn = request.getParameter("searchColumn"); String keyword = request.getParameter("keyword"); Map<String, Object> params = new HashMap(); params.put("searchColumn", searchColumn); params.put("keyword", keyword); User loginUser = (User) request.getSession().getAttribute("loginUser"); if (!"管理员".equals(loginUser.getUserType())) { params.put("id", loginUser.getId()); } UserService userService = new UserServiceImpl(); Map<String, Object> map = userService.list(params); request.getSession().setAttribute("list", map.get("list"));
Integer totalRecord = (Integer) map.get("totalCount"); String pageNum = request.getParameter("pageNum"); com.demo.util.PageBean<Object> pb = new com.demo.util.PageBean(Integer.valueOf(pageNum != null ? pageNum : "1"), totalRecord); params.put("startIndex", pb.getStartIndex()); params.put("pageSize", pb.getPageSize()); List list = (List) userService.list(params).get("list"); pb.setServlet("UserServlet"); pb.setSearchColumn(searchColumn); pb.setKeyword(keyword); pb.setList(list); request.getSession().setAttribute("pageBean", pb); request.getSession().setAttribute("list", pb.getList());
|
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 41 42 43 44
| if (user != null) { session.removeAttribute("loginUser"); } response.sendRedirect("login.jsp"); } else if ("validationCode".equalsIgnoreCase(action)) { String codeChars = "0123456789"; int charsLength = codeChars.length(); response.setHeader("ragma", "No-cache"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); int width = 90, height = 20; BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics g = image.getGraphics(); Random random = new Random(); g.setColor(getRandomColor(180, 250)); g.fillRect(0, 0, width, height); g.setFont(new Font("Times New Roman", Font.ITALIC, height)); g.setColor(getRandomColor(120, 180)); StringBuilder validationCode = new StringBuilder(); String[] fontNames = {"Times New Roman", "Book antiqua", "Arial"}; for (int i = 0; i < 4; i++) { g.setFont(new Font(fontNames[random.nextInt(3)], Font.ITALIC, height)); char codeChar = codeChars.charAt(random.nextInt(charsLength)); validationCode.append(codeChar); g.setColor(getRandomColor(10, 100)); g.drawString(String.valueOf(codeChar), 16 * i + random.nextInt(7), height - random.nextInt(6)); } HttpSession session = request.getSession(); session.setMaxInactiveInterval(5 * 60); session.setAttribute("validationCode", validationCode.toString()); g.dispose();
|
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
| sessionService.add(vo); this.redirectList(request, response); } else if ("delete".equals(action)) { long id = Long.parseLong(request.getParameter("id")); SessionService sessionService = new SessionServiceImpl(); sessionService.delete(id); this.redirectList(request, response); } else if ("edit".equals(action)) { Session vo = new Session(); vo.setId(Long.valueOf(request.getParameter("id"))); vo.setSessionName(Long.valueOf(request.getParameter("sessionName"))); vo.setSessionSeat(Long.valueOf(request.getParameter("sessionSeat"))); vo.setCreateTime(request.getParameter("createTime")); vo.setSessionDuration(request.getParameter("sessionDuration")); vo.setSessionText(request.getParameter("sessionText")); SessionService sessionService = new SessionServiceImpl(); sessionService.update(vo); this.redirectList(request, response); } else if ("get".equalsIgnoreCase(action) || "editPre".equalsIgnoreCase(action)) { Serializable id = request.getParameter("id"); SessionService sessionService = new SessionServiceImpl(); Session vo = sessionService.get(id); request.getSession().setAttribute("vo", vo); String to = "get".equalsIgnoreCase(action) ? "info" : "edit"; response.sendRedirect("session_" + to + ".jsp"); } else { this.redirectList(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 38 39 40 41 42 43 44 45 46 47 48
| String username = request.getParameter("username"); String password = request.getParameter("password");
String validationCode = request.getParameter("validationCode"); if (validationCode != null && !validationCode.equals(request.getSession().getAttribute("validationCode"))) { request.getSession().setAttribute("alert_msg", "错误:验证码不正确!"); request.getRequestDispatcher("login.jsp").forward(request, response); return; }
UserService userService = new UserServiceImpl(); Map<String, Object> params = new HashMap(); List<User> list = (List<User>) userService.list(params).get("list"); for (User user : list) { if (user.getUsername().equals(username) && user.getPassword().equals(password)) { request.getSession().setAttribute("loginUser", user); request.getSession().setMaxInactiveInterval(Integer.MAX_VALUE); request.getRequestDispatcher("UserServlet").forward(request, response); return; } } request.getSession().setAttribute("alert_msg", "错误:用户名或密码错误!"); request.getRequestDispatcher("login.jsp").forward(request, response); } else if ("register".equalsIgnoreCase(action)) { String username = request.getParameter("username"); String password = request.getParameter("password"); System.out.println("username=" + username); System.out.println("password=" + password); UserService userService = new UserServiceImpl(); Map<String, Object> params = new HashMap(); params.put("startIndex", 0); params.put("pageSize", Long.MAX_VALUE); List<User> list = (List<User>) userService.list(params).get("list"); for (User user : list) { if (user.getUsername().equals(username) ) { request.getSession().setAttribute("alert_msg", "错误:用户名已存在!"); request.getRequestDispatcher("register.jsp").forward(request, response); return; } } User vo = new User(); vo.setUsername(username); vo.setPassword(password); vo.setUserType("普通用户");
|
——————————PayStart——————————
项目链接:
https://javayms.github.io?id=141424392906201lw
https://javayms.pages.dev?id=141424392906201lw