Goods: Login page Login function implementation

Source: Internet
Author: User

Userservlet

1 //Login Function2      PublicString Login (httpservletrequest req, HttpServletResponse resp)throwsunsupportedencodingexception {3         /*4 * Encapsulate form data to user//Verify form data using service query If there is no Save error message user name or password error saving user data in order to echo5 * If there is a view status status of False save error message you did not activate save form data in order to echo forward to login.jsp login that success6 * Save the current query out of the user to the session to save the name of the current users to the cookie note Chinese to encode processing7          */8         //encapsulate form data to user9User Formuser = Commonutils.tobean (Req.getparametermap (), user.class);Ten         //Verifying form data Onemap<string, string> errors =Validatelogin (Formuser, Req.getsession ()); A         if(Errors.size () > 0) { -Req.setattribute ("Errors", errors); -Req.setattribute ("form", formuser); the             return"F:/jsps/user/regist.jsp"; -         } -         //to UserService's LOGINFF. -User User =Userservice.login (formuser); +         if(User = =NULL) { -Req.setattribute ("msg", "User name or password error"); +Req.setattribute ("User", formuser); A             return"F:/jsps/user/regist.jsp"; at}Else { -             if(!User.isstatus ()) { -Req.setattribute ("msg", "You have not activated"); -Req.setattribute ("User", formuser); -                 return"F:/jsps/user/regist.jsp"; -  in}Else { -                 //Save the current query out of user to session to save the name of the current users to the cookie note Chinese to encode processing toReq.getsession (). SetAttribute ("Sessionuser", user); +String loginname=user.getloginname (); -Loginname=urlencoder.encode (LoginName, "Utf-8"); theCookie cookie=NewCookie ("LoginName"), loginname); *                 //set the age of the cookie otherwise cookies only live in the browser memory $Cookie.setmaxage (60*60*24*10);//Save 10 daysPanax Notoginseng Resp.addcookie (cookie); -                 return"R:/index.jsp"; the                  +             } A         } the      +}

login.jsp The local cookie to determine whether the echo is consistent with the user received in the cookie to echo the user's priority higher

1<script type= "Text/javascript" >2$(function(){//Map<string<cookie name >,cookie<cookie itself >>3         //El expressions are executed first, so if you do not add double quotes before you execute JavaScript, you are going to be King eight.4         //get the user name in the cookie5            varLoginname=window.decodeuri ("${cookie.loginname.value}");6          //gets the echo user name7          if("${requestscope.user.loginname}")8          {9Loginname= "${requestscope.user.loginname}"; Ten          } One$ ("#loginame"). Val (loginname); A             -         }); -</script>

top.jsp User Login Judgment

1 <C:choose>2             <C:whenTest= "${empty Sessionscope.sessionuser}">3                 <ahref= "<c:url value= '/jsps/user/login.jsp '/>"Target= "_parent">Member Login</a>|&nbsp; 4      <ahref= "<c:url value= '/jsps/user/regist.jsp '/>"Target= "_parent">Registered Members</a>5             </C:when>6             <c:otherwise>7Member: ${sessionscope.sessionuser.loginname}&nbsp;&nbsp;|&nbsp;&nbsp;8           <ahref= "<c:url value= '/jsps/cart/list.jsp '/>"Target= "Body">My Shopping Cart</a>&nbsp;&nbsp;|&nbsp;&nbsp;9           <ahref= "<c:url value= '/jsps/order/list.jsp '/>"Target= "Body">My order</a>&nbsp;&nbsp;|&nbsp;&nbsp;Ten           <ahref= "<c:url value= '/jsps/user/pwd.jsp '/>"Target= "Body">Change Password</a>&nbsp;&nbsp;|&nbsp;&nbsp; One           <ahref= "<c:url value= '/jsps/user/login.jsp '/>"Target= "_parent">Exit</a> A             </c:otherwise> -         </C:choose>

Goods: Login page Login function implementation

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.