Session tracking (ask questions)

Source: Internet
Author: User

> to be able to uniquely identify users in a Web application, you must use session tracking technology.

> Session tracking technology can be implemented through the following technologies:

1)Cookie Technology: A cookie is a piece of textual information stored on the client and is passed between the client and the server with the user's request.

2)Session Technology: The Web server for the client to open up a piece of storage space, used to store client status information.

Session tracking is possible with both >cookie and sessions, but the differences are as follows:

1) A cookie is a message stored at the client and the session is stored on the server.

2) Only the string can be saved in the cookie, and any object may be saved in the session.

3) The information stored in the Sesson is invalidated when the browser is closed and the information stored in the cookie can persist for a long time.

4) Because users can delete cookies, it is common to keep some unimportant information in the cookie, and important information is stored in the session.

> In JSP, there are four ranges of objects:page,request,session , and application.

And then I'm going to show you my exception today:

Servlet:

//Create two cookies
     cookie username = new Cookie ("username", "clove Flower");
     cookie userpwd = new Cookie ("Userpwd", "1");
     //writes a cookie to the client
     Span style= "color: #999999;" >response.addcookie (username);     
      Response.addcookie (userpwd);
     if (1 = = 1) {       
      //go to the page to view cookie information
       response.sendredirect (" cookie1_show.jsp ");
    }

Jsp:

   //Read all cookies and return an array of cookies
cookie[] cookies = request.getcookies ();
//Traversal cookie array
for (int i =0;i<cookies.length;i++) {
Cookie cookie = cookies[i];
//Judging by cookie name
if (Cookie.getname (). Equals ("username")) {
out.println ("User name is:" +cookie.getvalue ());
     }
if (Cookie.getname (). Equals ("Userpwd")) {
out.print ("Password is:" +cookie.getvalue ());
     }
    }

Then the error is: Control character in cookie value, consider BASE64 encoding your value

Think about it, feel that they have written nothing wrong, and then the "Lilac flower" changed to "admin" just fine.

Which big God can you explain to me after watching? Why not?

Session tracking (ask questions)

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.