Userservlet
1 //Change Password2 PublicString Updatepassword (httpservletrequest req, HttpServletResponse resp)3 {4 /*5 * 1, package form data to Userzhong6 * 2\ get UUID from session7 * 3. Use UID and Oldpass and newpass in the form to invoke Serviceff8 * If exception is saved, the exception message is forwarded to pwd.jsp in Request9 * 4, Save the Success information to the requestTen * 5, forward to msg.jsp One */ A -User Formuser = Commonutils.tobean (Req.getparametermap (), user.class); -User user= (user) Req.getsession (). getattribute ("Sessionuser"); the if(user==NULL) - { -Req.setattribute ("msg", "You are not logged in"); - return"F:/jsps/user/login.jsp"; + } - + Try { A Userservice.updatepassword (User.getuid (), Formuser.getnewpass (), at Formuser.getloginpass ()); - //no exception was thrown to save success information -Req.setattribute ("msg", "Change Password succeeded"); -Req.setattribute ("Code", "Success"); - return"F:/jsps/msg.jsp"; -}Catch(userexception e) { inReq.setattribute ("msg", E.getmessage ());//Save exception information to request -Req.setattribute ("User", formuser); to return"F:/jsps/user/pwd.jsp"; + } - the}
UserService
1 //Change Password2 Public voidUpdatepassword (String uid, string newpass, string oldpass)3 throwsuserexception {4 5 Try {6 //Verify old Password7 BooleanBOOL =Userdao.findbyuidandpassword (UID, oldpass);8 if(!bool) {9 Throw NewUserexception ("Old password error");Ten } One //Change Password A Userdao.updatepassword (UID, newpass); -}Catch(SQLException e) { - //TODO auto-generated Catch block the Throw NewRuntimeException (e); - } - -}
Goods: Change Password function implementation