SPRING+HIBERNATE+STRUTS2 integration of the implementation of the login function

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.