Click to remember the password
login.jsp
String host = Request.getservername (); Cookie cookie = new Cookie ("Session_login_username", USERNAME); Save user name to Cookie cookie.setpath ("/"); Cookie.setdomain (host); Cookie.setmaxage (99999999); Response.addcookie (cookie); if (Paramutils.getbooleanparameter (Request, "Savepassword")) { //Save password to cookie, note need to encrypt cookie = new Cookie (" Session_login_password ", Md5.encode (U.getpassword ())); Cookie.setpath ("/"); Cookie.setdomain (host); Cookie.setmaxage (99999999); Response.addcookie (cookie); }
The second step, when the user visits the website, if detected does not log in, then carries on the following judgment.
index.jsp
String Usernamecookie = null; String Passwordcookie = null; cookie[] cookies = request.getcookies (); if (cookies = null) {for (Cookie cookie:cookies) { if ("Session_login_username". Equals (Cookie.getname ())) {
usernamecookie = Cookie.getvalue (); Gets the user name of the cookie } if ("Session_login_password". Equals (Cookie.getname ())) { Passwordcookie = Cookie.getvalue (); Get the password for the cookie } } if (Usernamecookie! = NULL && Passwordcookie! = null) {//If there is an if (login.ch Ecklogin (Usernamecookie, Passwordcookie)) { //Login Successful processing }else{ //Login unsuccessful processing } }
JSP enables automatic website login via session and Cookie