Four kinds of conversation tracking technology

Source: Internet
Author: User

Session tracking is a flexible, lightweight mechanism that enables State programming on the web to become possible.

HTTP is a stateless protocol that responds when a user makes a request, and the connection between the client and the server is discrete and non-contiguous.
When a user transitions between multiple pages in the same site, there is no way to determine whether the same customer is the same, and session tracking technology solves the problem.
When a customer switches between multiple pages, the server saves the user's information.
There are four ways to implement session tracking technology: URL Rewriting, hiding form fields, cookies, session.

1).Hide form fields:<input type= "hidden" >, ideal for session applications that require large amounts of data storage.
2). URLrewrite: URLcan be appended with the parameters, and the server's request sent together, these parameters are the name/value pairs. See http://blog.csdn.net/xh16319/article/details/8464055
3). Cookies:aCookiesis a small, named data element. Server UseSet-cookiethe header marks it asHTTP
A part of the response is delivered to the client and the client is requested to saveCookiesvalue, using one of the subsequent requests to the same server
Cookiesheaders are returned to the server. Compared with other technologies,CookiesOne of the advantages is that after the browser session ends, even
It can still retain its value after the client computer restarts. See: http://blog.csdn.net/xh16319/article/details/8464319
4). Session: UsingsetAttribute (String str,object obj)method to bundle an object into a session

Implementing URL Rewriting

URL rewriting is used when the client browser does not support cookies (described in the next chapter), when the client browser requests the server, the URL address is followed by a parameter similar to "sessionid=***", and the server side obtains the session value by acquiring 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 makes a request for the first time, the service side defaults to URL rewriting, which is the SessionID written 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, no longer URL rewriting. If not, continue with URL rewriting.

URL rewriting can be done through the Encodeurl (String url) method of the Response object.

public string encodeurl (string url);
Encodes the URL that contains the SessionID. If the encoding is not required, the URL is returned 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 request, but the session cannot be maintained by means of a non-URL (such as a cookie).
So all URLs provided to the servlet should be run in this way to ensure that session tracking works in all browsers.

Hidden fields and URL rewriting 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, and there are many lengthy processing tasks involved.


Four kinds of conversation tracking technology

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.