Software 152 Liu Anmin
Front-End Code:
<form id= "LoginForm" action= "${pageContext.request.contextPath}/user_login.action" method= "POST" Novalidate= "Novalidate" > <table><tbody><tr> <th> user name: </TH><TD > <input type= "text" id= "username" name= "username" class= "text" maxlength= "" onclick= "Toggle (' Div1 ')"; ><span><s:fielderror fieldname= "username"/></span></td> </tr> <tr ><th> password:</th><td> <input type= "password" id= "password" name= "password" class= " Text "maxlength=" "autocomplete=" Off "onclick=" toggle (' Div1 ') ";/><span><s:fielderror fieldname=" Password "/></span></td> </tr> <tr> <td><input type=" Submit "class=" Submit "value=" Login > </td></tr></tbody></table></form>
Logged in action:
//Front Desk: Login function@InputConfig (resultname= "Logininput") PublicString Login () {User Existuser=userservice.login (user); if(existuser==NULL){ This. Addactionmessage ("User name or password error or user not activated! "); return"Logininput"; }Else{servletactioncontext.getrequest (). GetSession (). SetAttribute ("Existuser", existuser);return"Loginsuccess"; } }
Logged-in service:
// Business Layer Login method Public User login {// TODO auto-generated method stub System.out.println ("username : "+user.getusername () +" Password: "+User.getpassword ()); return userdao.login (user); }
Log in DAO:
@Override Public User Login (user user) { // TODO auto-generated method stub String queryString = "from User WHERE username =? and password =? " ; Listthis. gethibernatetemplate (). Find (Querystring,user.getusername (), User.getpassword ()); if (List.size ()!=0) { return list.get (0); } return NULL ; }
Configuration struts.xml:
<!--Configure the user's action-- class= "Useraction" method= "{1}" > <result name= "Logininput" >/ web-inf/jsp/login.jsp</result> <result name= "loginsuccess type=" Redirectaction ">index</result > </action>
Configuration applicationcontext.xml:
class= "Com.ansibee.shop.web.action.UserAction" scope= "prototype" > class= " Com.ansibee.shop.service.UserService "> class=" Com.ansibee.shop.daoImpl.UserDAOImpl "> <property name= "Sessionfactory" ref= "Sessionfactory" ></property></bean>
SPRING+HIBERNATE+STRUTS2 integration of the implementation of the login function