<%@ 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>session1.jsp</title></Head><Body><%stringCardid= null; Cookie[] Cks= Request.getcookies (); if (cks!)= null){//If a cookie has been set, the value is obtained and saved to the variable pname for (int i=0;i<cks.length; i++) {if (Cks[i].getname (). Equals ("Cardid")) Cardid= Cks[i].getvalue (); } }%><formAction= "session2.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>
<%@ 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>session2.jsp</title></Head><Body><% @pageImport= "Java.net.URLEncoder"%><% @pageImport= "Com.shuyinghengxie.bank.CardDAO"%><%@ Pagelanguage= "Java"ContentType= "text/html; charset=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><%//settings do not cache pages Response.setheader("Cache-control", "No-cache");//Login Successful timed jump//response.setheader ("Refresh", "2; URL=http://www.baidu.com ");//page Jump//response.sendredirect ("success.jsp"); String Kahao= 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 ("kah888o", Kahao); Set Expiration Time Ck.setmaxage (10*24*60*60); Send Response.addcookie (CK); Create Session Session.setattribute ("Kahao", Kahao); Session.setattribute ("username", "John Doe"); Set session timeout time//default setting is 20 minutes//If more than 20 minutes without any request sent to the server, the session expires Session.setmaxinactiveinterval (30); Response.sendredirect ("session3.jsp"); } else {out.write ("Login Failed"); }}%></Body></HTML></Body></HTML>
<%@ 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>session3.jsp</title></Head><Body><%objectKahao= Session.getattribute ("Kahao"); if (Kahao!)= null){out.write ("You have Landed");} else{Out.write ("Not yet logged in");} %><ahref= "session4.jsp">Sign Out</a></Body></HTML>
<%@ Pagelanguage= "Java"ContentType= "text/html; charset=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>session4.jsp</title></Head><Body>has exited! <%session.invalidate() ; Destroy SESSION//2 seconds after jump Response.setheader ("Refresh", "2; URL= session3.jsp ");%></Body></HTML>
Then click to exit, jump to Session4 page, this page timed 2 seconds jump Session3
It is possible to see that the login has exited
Session login browsing, and implementation of the session logout login