Four kinds of Session tracking technology

Source: Internet
Author: User

It programmer development must-all kinds of resources download list, the most complete IT resources in history, personal collection summary.

Session tracking is a flexible, lightweight mechanism that makes State programming on the web possible.
HTTP is a stateless protocol, and whenever a user makes a request, the server responds, and the connection between the client and the server is discrete and discontinuous.
Session tracking technology solves this problem when a user transitions between multiple pages of the same site and cannot determine whether it is the same customer.
When a customer switches between multiple pages, the server saves the user's information.
There are four ways to implement session-tracking techniques: url Rewriting, hidden form fields, cookies, sessions.

1). Hide form fields: <input type= "hidden" > is ideal for session applications that require a large amount of data storage.
2). URL overrides: URLs can be appended with parameters, sent along with the server's request, which are name/value pairs. See http://blog.csdn.net/xh16319/article/details/8464055
3). Cookie: A cookie is a small, named data element. The server uses the Set-cookie header to use it as an HTTP
Part of the response is routed to the client, where the client is requested to save the Cookie value, and a subsequent request to the same server uses a
The Cookie header returns it to the server. One advantage of cookies, compared with other technologies, is that after the browser session is over, even
It can still retain its value after the client computer restarts. See: http://blog.csdn.net/xh16319/article/details/8464319
4). Session: Binding an object to a conversation using the setattribute (String str,object obj) method


Implementing URL Rewriting

URL overrides are used in the case where the client browser does not support cookies (described in the next chapter), when the client browser requests the server, and the URL address is followed by a parameter similar to "sessionid=***", which gets the session value by obtaining the SESSIONID keyword.

When the program first accesses the server side, the service side does not confirm that the client browser supports cookies. Therefore, when the server first makes a request, the service side defaults to the URL rewrite, which is to write the SessionID to the URL address.

Core code: String Sessionid=request.getrequestedsessionid ();

When a client sends a request, the server automatically checks to see if the client has cookies enabled based on the information submitted to the client browser, and if enabled, URL rewriting is no longer done. If not, continue with the URL rewrite.

URL rewriting can be done through the response object's Encodeurl (String url) method.

public string encodeurl (string url);
Encodes the URL that contains the SessionID. If no encoding is required, return the URL directly.
The servlet engine must provide a URL encoding method, because in some cases we will have to rewrite the URL.
For example, a valid session is included in the response to the request, but this session cannot be maintained by means other than a URL (such as a cookie).
So all URLs provided to the servlet should be run this way to ensure that session tracking works correctly in all browsers.

Hidden fields and URL overrides have a common advantage:
They can still work if the cookie is disabled or not supported at all.
Disadvantages:
All pages must be the result of a form submission, as well as a lot of lengthy processing work.

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.