jsp+mysql大学校园二手交易平台开发+数据流图+ER图(10)
时间:2017-01-10 13:09 来源:毕业论文 作者:毕业论文 点击:次
user.setStatus("0"); request.setAttribute("user", user); if(!valid){ request.setAttribute("operInfo", ""); request.getRequestDispatcher("/register.jsp").forward(request, response); return; } UserService userService = new UserService(); try{ User findUser = userService.getByUsername(username); if(findUser!=null){ throw new MyException("该账号已经存在,请注册其它账号"); } userService.add(user); request.setAttribute("operSuccessInfo", "注册成功"); request.setAttribute("successUrl", "login.jsp"); request.getRequestDispatcher("/success.jsp").forward(request, response); }catch(Exception e){ request.setAttribute("operInfo", e.getMessage()); request.getRequestDispatcher("/register.jsp").forward(request, response); } 4.1.2 用户登录模块 根据用户输入的用户名和密码,首先判断用户名是否为空,如果为空,则系统要求重新输入;如果不为空,则与数据库中用户信息表做比较,若与记录一致,则进入网站浏览网页,否则提示错误,要求重新输入。 用户登录图如图4.2所示。 图 4.2 用户登录 用户登录核心代码: public void login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String username = request.getParameter("username"); String password = request.getParameter("password"); boolean valid = true; if(StringUtils.isEmpty(username)){ request.setAttribute("usernameError", "账号不能为空"); valid=false; }else if(username.length()>20){ request.setAttribute("usernameError", "账号长度不能大于20位"); valid=false; }else if(username.length()<5){ request.setAttribute("usernameError", "账号长度不能小于5位"); valid=false; }else if(username.matches("/^[a-z|A-Z|0-9]+$/")){ (责任编辑:qin) |