The initial solution of conversation management in Jsp/servlet learning three

Source: Internet
Author: User

Because of the stateless nature of HTTP, Session management or session tracking becomes an unavoidable topic in Web application development. By default, a Web server cannot differentiate whether an HTTP request is a first-time access. For example, a Web mail application requires users to log in before they can view the message, so when the user enters the appropriate user name and password, should not be prompted again to require users to log in, it should be remembered that those users have logged in. In other words, you should be able to manage users ' sessions.

  URL rewriting

  URL rewriting is a session-tracking technique that adds one or more tokens to a query string of URLs, usually in the form of Key=value, as follows:

Url? Key-1=value-1&key-2=value-2

Notice that the URL and the tokens use Hello (?). ), divided by the token (&) between tokens.

URL rewriting is appropriate for tokens without having to pass too many URLs, but it has the following limitations:

The maximum length of the URL on some browsers is 2000 strings;

To pass to the next resource, you need to insert the value into the link, in other words, the static page is difficult to pass the value;

URL rewriting needs to be done on the service side, all links must have values, so when a page has a lot of links, the process is a big challenge.

Certain characters, such as spaces, and question marks, must be encoded with Base64;

All information is visible and in some cases inappropriate.

Because of the above limitations, URL rewriting is only appropriate for information that is passed between only a few pages and is not sensitive to information.

  Cookies

  Cookies are a small piece of information that can be automatically interacted between a browser and a Web server, so cookies can be stored across multiple pages to pass information. Cookies are part of the HTTP header, and their transmissions are controlled by the HTTP protocol. In addition, you can control the effective time of cookies. Browsers usually support up to 20 cookies per website.

The problem with cookies is that users can refuse to accept cookies by changing their browser settings.

To use cookies, you need to be familiar with the Javax.servlet.http.coockie class as well as the HttpServletRequest and HttpServletResponse two interfaces.

You can create a cookie by passing the name and value two parameters to the constructor of the Cookies class:

Cookie cookie = new Cookie (name,value);

Here is an example of a cookie that creates a language selection:

Cookie Languageselectioncookie = new Cookie ("language", "Italian");

After you create a cookie object, you can set the Domain,path and MaxAge properties. Where the MaxAge property determines when the cookie expires.

  HttpSession Object

Of all the session tracking technologies, the HttpSession object is the most powerful and versatile. A user can have and have at most one httpsession, and will not be accessed by other users. The HttpSession object is created automatically when the user first accesses the site, and you can get the object by calling HttpServletRequest's GetSession method.

PS: This is a preliminary understanding of the session follow-up release details Jieboven

The initial solution of conversation management in Jsp/servlet learning three

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.