In-depth understanding of HTTP Session

Source: Internet
Author: User
Tags session id

In- depth understanding of HTTP SessionSession in Web development is a very important concept, the concept is very abstract, difficult to define, but also the most confusing a noun, is also the most abused name, in different occasions, the meaning of the session is also very dissimilar. Only the HTTP Session is discussed here.   To illustrate the problem, this is based on the Java servlet understanding of the concept and principle of the session, where the servlet has covered the JSP technology, because the JSP will eventually be compiled into a servlet, both have the same essence.   in Java, the session object for HTTP is represented by Javax.servlet.http.HttpSession.  1, Concept: Session represents the server and browser of a conversation process, the process is continuous, or can be intermittent. In the servlet, the session refers to the object of the HttpSession class, the concept to this end, it may be very vague, but only after reading this article, can really have a deep understanding. &NBSP;2, Session creation time is: a common misconception is that the session is created when there is client access, but the fact is that it is not until a server-side program calls Httpservletrequest.getsession (True) Such statements are created, note that if the JSP is not displayed using <% @page session= "false"%> close the session, the JSP file will be automatically added to the servlet when it is translated into a single statement HttpSession Session = Httpservletrequest.getsession (TRUE), which is also the origin of the hidden session object in the JSP. Because the session consumes memory resources, if you do not intend to use the session, you should close it in all JSPs.   Extension: 1), access to *.html static resources because it will not be compiled into a servlet, it does not involve the session of the problem. 2), when the JSP page does not explicitly prohibit the session, when the browser opens the first time to request the JSP, the server will automatically create a session for it, and give it a sessionid, sent to the client's browser. When the client then requests the other resources in the application, it is automatically added on the request header: The first time the cookie:jsessionid= client gets the session ID so that the server receives the session ID when the request is received. And based on the ID found in memory before the creation of the SessioN object, provided to the request for use. This is also the basic principle of using the session----do not understand this, will never understand the principle of the session. Here are two requests for the same JSP, request header information: Through the diagram can be clearly found, the second time the request, the session ID has been added to the information.
 3, Session Delete time is: 1) session timeout: Timeout refers to a continuous period of time the server did not receive the client's request for the session, and this time exceeded the server Set session timeout maximum time. 2) Program Call Httpsession.invalidate () 3) server shutdown or service stop  4, session stored in: server-side memory. However, the session can be managed in a special way for persistence. &NBSP;5, session ID is from where, how SessionID is used: When the client first requests the session object, the server will create a session for the client, and will be a special algorithm to calculate the ID of a session, Used to identify the session object, when the next time the browser (session continues to be valid) request other resources, the browser will secretly put SessionID into the request header, the server received the request to get the SessionID of the request, The server finds the session of the ID to be returned to the requestor (Servlet) for use. A session can only have one session object, for the session is only recognized ID not identify.  6, session will be deleted because the browser is closed? No, the session will only be closed by the way mentioned above.  7, same client machine multiple requests for the same resource, session? In general, each request will be created with a new session.   In fact, this is not necessarily, summed up: For multi-label browser (such as 360 browser), in a browser window, multiple tabs at the same time access to a page, session is a. For multiple browser windows, at the same time or a short distance to access a page, the session is multiple, and the browser process. The session is the same for a single browser window that accesses different resources of the same application directly into the URL.  8, session is a container that can hold any object during the session.  9, session because of requests (Request object), the same session with multiple request shared a Session object, you can directly from the request to get to the session object. &NBSP;10, in fact, the creation and use of the session is always on the server, and the browser has never been a session object. However, the browser can request that the servlet (JSP is also a servlet) to get information about the session. The client browser really tightly gets the session ID, and this pairis not visible to the browser operator, and the user does not need to be concerned about which session they are in.

In-depth understanding of HTTP Session

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.