Session login browsing, and implementation of the session logout login

Source: Internet
Author: User

<%@ 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

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.