Session: Users open a browser, click multiple hyperlinks, access the server multiple Web resources, and then close the browser, the entire process is called a session.
The difference between a session and a cookie:
Cookies:
A cookie is a client-side technology in which a program writes each user's data to a user's browser in the form of a cookie. When users use a browser to access Web resources on the server, they take their own data. In this way, the Web resource handles the user's own data.
Session:
Session is a server-side technology, using this technology, the server at run time can be used for each user's browser to create a unique session object, because the session for the user browser exclusive, so the user access to the server's Web resources, Can put their own data in the session, when the user to access other Web resources on the server, the other Web resources from the user's own session to remove data for the user Service.
In Java, the cookie is encapsulated into the Javax.servlet.http:Cookie class. Each cookie is an object of the cookie class.
cookies have non-cross-domain names .
Cookie Expiration : The maxage of the cookie determines the validity period of the cookie. Getmaxage () and Setmaxage () Read and write MaxAge properties. MaxAge is positive, it means that it disappears automatically after maxage seconds. MaxAge is negative, closing the browser window is invalid. The default maxage of -1,maxage is 0 to delete the cookie.
cookie modification, deletion : Delete a cookie, just create a new cookie with the same name. and set MaxAge to 0. and add to response to overwrite the original cookie.
Session life cycle : The server updates the session's last access time and maintains the session.
duration of Session :
Common methods of Session :
Setmaxinactiveinterval (int interval)//Set the effective time, note the unit in seconds.
Getmaxinactiveinterval (int interval)//Get effective time
SetAttribute (String name, object value)://Adds an object to the session scope with a specified name
GetAttribute (String name)//Gets the object in scope by making a name
RemoveAttribute (String name)//Remove an object from the scope by making a name
Getattributenames ()//Get all the objects in scope
Session and Cookie