The Session__js of JSP

Source: Internet
Author: User
Tags session id

The session is a global variable and is the proxy of the browser thread on the server side. As soon as the Web service program is open, the session will exist, and when you first visit, the session will automatically assign you one session ID, so the session is newly established, so Session.isnew () is true. When you refresh the page, the session ID persists (Session.getid () unchanged) and does not disappear, so Session.isnew () is false. Unless you close the Web site you are visiting, or close the session (Session.invalidate ()), it Disappears (Session.getid () is changed) and IsNew () is true.
Two methods Session.isnew () to determine if it is a new session
Session.getid () get this session ID

Session.isnew () is true when all browsers are closed and then logged in again
Session.isnew () is false when a new browser is opened each time with a different user login. Session.getid () is the same.
That is, the session ID is equivalent to the ID assigned by the Web server to this browser process when a browser process (not a thread) is opened

Common methods:

Long create_time = Session.getcreationtime (); Session creation Time
Long access_time = Session.getlastaccessedtime ();//session Last access time

Print the attribute value in the session

Enumeration elements = Session.getattributenames ();
while (Elements.hasmoreelements ()) {
String id = (string) elements.nextelement ();
}

Response.setheader ("Refresh", "5;url=/session_filter_listener/index.jsp");//Refresh every 5 seconds and navigate to index.jsp

Related Article

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.