Sessions and cookies at a glance

Main line: save user data

Session management:
Concept: A web session can be simply understood as: the user opens a browser, visits a certain web site,
clicks multiple hyperlinks on this site, accesses multiple web resources on the server, and then closes the browser.
The whole process is called a session.
context is a global resource that can be used by all users

cookie: cookie is a client-side technology. The programmer writes the data of each user to the
user's respective browser in the form of a cookie. When the user uses the browser to access the web
resources in the server, they will bring their own data with them. go. In this way, the web resource deals with the user's own data. session: session is a server-side technology. Using this technology, the server can create an exclusive session object for each user's browser
at runtime . Since the session is exclusive to the user's browser, the user is accessing the server's web resources. When the user accesses other microblog resources in the server and other web resources, the other web resources take out data from the user's respective session to serve the user. Cookie solution: bring the cookie to the browser through the response, get the user data, find the request addcookie, create a cookie object , get cookies in the request, get the cookie creation details set value, get value get the value of the cookie setMaxAge, getMaxAge: control the validity period of the cookie If it is not set, the validity period of the cookie is the life cycle of the browser setPath getOath method: set the effective directory of the cookie setDomain, getDomain method: set the effective domain browser refuses to accept. sina.com generally has no effect getName method: control the name of the cookie. Cookie application: 1:















Display the user's last visit time: For the code, see the message picture in QQ Friends Shuaizhong.


Cookie details 1. A cookie
can only identify one type of information, and it contains at least one name and set value that represents the information.
2. A web site can send multiple cookies to a web browser, and a web browser can also
store multiple web browsers. Site-provided cookies.
3. Browsers are generally only allowed to store 300 cookies, and each site can store up to 20
cookies. The size of each cookie is limited to 4KB.
4. If a cookie is created and sent to the browser, it is a session-level cookie by default. After the
user exits the browser, it is deleted. If you want to store the cookie on disk after exiting, you need to use maxage
and gives a time in seconds. Setting the maximum time limit to 0 commands the browser to
delete the cookie. 5. The path must be consistent when deleting the cookie, otherwise it will not be deleted.

Two: cookie application to check the last shopping situation
.

Session Introduction Session: Session is a server-side technology. Using this technology, the server can create an exclusive session object for each user's browser
at runtime . Since the session is exclusive to the user's browser, the user is accessing the server. When the user accesses other microblog resources in the server, when other web resources are used, the data taken from the user's respective session by other web resources is User Services.





A session serves only one object.


The life cycle of the session object:
Session creation timing: when you access the getsession code for the first time, not when you visit the website.
Timing of session destruction: The session will not be destroyed immediately when the server is shut down, but will be automatically destroyed 30 minutes after creation.
The destruction time can be controlled in web.xml, and the sub-tag <session-timoeut> of the tag named session-config tag can be used to control
the destruction time of the session. It can also be controlled by code.

The code is as follows: session.invalidate(); to destroy the session.


The working principle of getsession's session retrieval:
session will create an id number for the session when the session is created and
write the id back to the browser in the form of a cookie. The browser will bring the id number to the server when it next accesses the server. The server finds the session by id number
and uses it.
How sessions work: The solution to the problem when a website is disabled from using cookies is to
use URL rewriting.

Pay attention to the details of the session, the session is based on the cookie new window, and the tab is based on the original session


Common cases of session shopping: use session to implement simple shopping functions:
session is used for shopping sites with a small number of users.

Session application user login:

 

 

 

 


Three domain objects of servlet: request, session, servletcontext three domain objects


Key point: In a specific case, call special container and domain objects: request, session, servletcontext

One: The specific situation of request: after the program generates data, it is useless to display it, then use request.
Two: session, after the data is generated and displayed, the data will be used after a period of time, then the session will be used.
Three: servletcontext: After the data is generated, I show the data to the user. I will not only use it for a while,
but also use it for others, such as chat rooms. Then use servletcontext.

Data Fingerprint (Data Digest): Encrypt data. password to save data

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324865938&siteId=291194637