标签:
UserServlet
1 //修改密码 2 public String updatePassword(HttpServletRequest req, HttpServletResponse resp) 3 { 4 /* 5 * 1、封装表单数据到userzhong 6 * 2\从session中获取uuid 7 * 3、使用uid 和表单中的oldPass和newpass来调用serviceff 8 * 如果出现异常 保存异常信息到request中 转发到pwd.jsp 9 * 4、保存成功信息到request中 10 * 5、转发到msg.jsp 11 */ 12 13 User formUser = CommonUtils.toBean(req.getParameterMap(), User.class); 14 User user=(User) req.getSession().getAttribute("sessionUser"); 15 if(user==null) 16 { 17 req.setAttribute("msg", "您还没有登录"); 18 return "f:/jsps/user/login.jsp"; 19 } 20 21 try { 22 userService.updatePassword(user.getUid(), formUser.getNewpass(), 23 formUser.getLoginpass()); 24 //没有抛出异常保存成功信息 25 req.setAttribute("msg", "修改密码成功"); 26 req.setAttribute("code", "success"); 27 return "f:/jsps/msg.jsp"; 28 } catch (UserException e) { 29 req.setAttribute("msg", e.getMessage());//保存异常信息到request中 30 req.setAttribute("user", formUser); 31 return "f:/jsps/user/pwd.jsp"; 32 } 33 34 }
UserService
1 // 修改密码 2 public void updatePassword(String uid, String newPass, String oldPass) 3 throws UserException { 4 5 try { 6 // 校验老密码 7 boolean bool = userDao.findByUidAndPassword(uid, oldPass); 8 if (!bool) { 9 throw new UserException("老密码错误"); 10 } 11 // 修改密码 12 userDao.updatePassword(uid, newPass); 13 } catch (SQLException e) { 14 // TODO Auto-generated catch block 15 throw new RuntimeException(e); 16 } 17 18 }
标签:
原文地址:http://www.cnblogs.com/xiaoying1245970347/p/4770951.html