Four session tracking technologies, four types of JSP range

Source: Internet
Author: User

The two questions on the Internet search the answer is the same, but my collection of notes that this is two questions, there are different answers, so here to comment.

four types of session tracking technology

Cookie,url Rewrite, session, hidden fields

Cookies : A name/value pair passed to the browser by the server in an answer header . The time the browser is saved is specified by the cookie's expiration time attribute. When a browser sends a request to a server, it checks its saved cookie and includes all cookies received from the same server in the request header.

For the first time, all through The URL is passed, that is, the URL followed by an ID identifier. It then determines whether the client accepts cookies, accepts them, and stores them in cookies. If not accepted, the URL is still used, that is, the ID is stored in each URL.

Session Tracking: Does not transfer all state information directly between the browser and the server, but simply passes the identifier (Session ID). The browser sends SessionID, and the server keeps track of all the information associated with the session. The delivery of SessionID can be done through cookies and URL replication techniques, and most containers support both technologies. The server cannot tell if the user is shutting down the browser, so closing the browser means that all session data associated with the previous session remains on the server until the session times out and the server destroys the session image.

? There are several ways to track the session IDs of requests in the same session, mainly with cookies and URL replication.

URL Replication : Put the session The ID code is in the URL.

Example:counter.jjsp;jsessionnid=be8d697876787876befdbde898789098980

This enables session tracking even if the browser does not support cookies.

for URL replication, the server extracts the session ID from the requested URI and associates the request with the corresponding session, and then, when accessing the session data, the JSP page is processed in exactly the same way as the cookie is used to track the session ID. So the implementation of Sesssion relies on cookie or URL replication technology.

If you want to provide session tracking for browsers that do not support cookies, you must use the <c:url> behavior to replicate all URLs in the application. This means that all pages in the application (at least those with references to other pages) must be JSP pages so that the page reference is dynamically encoded, and if a UR is omitted, the service loses track of the session.

Hide form fields : Hiding form fields is the session The ID is added to the HTML hidden table consignments (type hidden input).

Redirect and forward

You can use two methods to invoke another page, redirect, and forward.

Forward: <jsp:forward page= "userinfo.jsp"/>

forwarding , the JSP container uses an internal method to invoke the target page, and the new page continues to process the same request, and the browser does not know that the process involves multiple pages. The browser URL will remain intact.

Redirect: <c:redirect url= "userinfo.jsp"/>

REDIRECT differs from forwarding, when redirected, the first page notifies the browser of a request to send a new target page. The URL displayed by the browser becomes the URL of the new page.

Redirection is slower than forwarding because the browser has to make a new request.

Also, because redirection produces a new request, objects within the request scope will no longer be available after a redirect.

Four ranges of JSPs

Page,request,session,application

Page No is a representation of the objects and properties associated with a page. A page is represented by a compiled Java servlet class (which can have any include directives, but no include actions). This includes both Servlets and JSP pages that are compiled into Servlets

request is an object and property that represents a request that is made to a WEB client. A request may span multiple pages, involving multiple WEB components (due to the relationship of the forward directive and the include action)

A session is a representation of the objects and properties associated with a user experience for a WEB client. A Web session can and will often be requested across multiple clients

Application is a representation of objects and properties related to the entire WEB application. This is essentially a global scope that spans the entire WEB application, including multiple pages, requests, and sessions

Four session tracking technologies, four types of JSP range

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.