<% @pageImport= "Java.net.URLDecoder"%><% @pageImport= "Sun.security.util.Length"%><%@ Pagelanguage= "Java"ContentType= "text/html; charset=utf-8"pageencoding= "UTF-8"%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Insert Title here</title></Head><Body> <%stringCardid= null; Cookie[] Cks= Request.getcookies (); if (cks!)= null){//If a cookie has been set, then the value is given and placed in the value of the card number text box for the for (int i=0;i<cks.length; i++) {if (Cks[i].getname (). Equals ("Cardid")) Cardid= Cks[i].getvalue (); } }%><formAction= "cookie2.jsp"Method= "POST">Card number<inputtype= "text"name= "Cardid"value= "<% if (cardid! = null) out.println (cardid);%>"><BR>Password<inputtype= "Password"name= "Password"><BR><inputtype= "Submit"value= "Submit"></form></Body></HTML>
<% @pageImport= "Java.net.URLEncoder"%><% @pageImport= "Com.shuyinghengxie.bank.CardDAO"%><%@ Pagelanguage= "Java"ContentType= "text/html; charset=utf-8"pageencoding= "UTF-8"%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Insert Title here</title></Head><Body><%stringKahao= Request.getparameter ("Cardid"); String Password= Request.getparameter ("password"); if (Kahao==null| | | password==null|| Kahao== "" || Password== "" ) {out.write ("please login correctly");} else{Carddao CD= newCarddao (); if (Cd.checklogin (Kahao, password)) {//out.write ("landed successfully"); Response.getwriter (). Write ("Validate Pass"); Create Cookie Cookie CK= newCookies ("Cardid", Kahao); Set Expiration Time Ck.setmaxage (10*24*60*60); Send Response.addcookie (CK); Response.sendredirect ("a.jsp"); } else {out.write ("Login Failed"); }}%></Body></HTML>
<% @pageImport= "Java.net.URLDecoder"%><%@ Pagelanguage= "Java"ContentType= "text/html; charset=utf-8"pageencoding= "UTF-8"%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Insert Title here</title></Head><Body>Landing Success! </Body></HTML>
At this point, click Back to find the text box has just logged in account, even if the refresh still exists
JSP remembers the user name with a cookie and is displayed in a text box the next time you log in (just a cookie for almost three hours, ⊙﹏⊙ b Khan)