> 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)