The cookie mechanism uses the client-side hold state.
The session mechanism takes the server-side hold state.
###########################################################################################
How the session Works
The first time a user accesses a page of the server, the server assigns a session object to the client, specifying a unique ID for the session object, and sending the ID number to the client and writing to the cookie, allowing the client to establish a one-to-one relationship with the server-side session.
When the user continues to access other resources on the server, the server no longer assigns the user a new session object until the user closes the browser, times out, or calls the session's invalidate () method to invalidate it, and the client-server session ends.
When the user re-opens the browser to the Web site, the server will re-assign the user a Session object and reassign the SessionID.
Common methods of Session
1. Public Voidsetattribute (String name,object value)
Sets the value of the property of the specified name and adds it to the session scope. If this property exists within the session scope, the value of the property is changed.
2. Public Objectgetattribute (String name)
Takes the value of the property of the specified name in the session scope, returns an object, or returns NULL if the property does not exist
3. Public Voidremoveattribute (String name)
Removes the property of the specified name, and an exception occurs if the property does not exist.
4. Public Voidinvalidate ()
Invalidate the session. You can invalidate the current session immediately, and all the objects stored in the session are no longer available.
5. Public Stringgetid ()
Gets the ID of the current session. This ID is a unique identifier on the server side, and the only data that the session object sends to the browser is SessionID, which is typically stored in a cookie.
###########################################################################################
Built-in objects for JSPs
Request: Encapsulates the user-submitted information, using the appropriate method of the object to obtain the user-submitted information.
Response: A dynamic response to a user's request to send data to the client.
Session: It is created automatically when the first JSP page is loaded, completing the conversation period management.
Out: Used to output various data.
Page: is an instance of the current page-converted Servlet class.
Exception: Exception handling
PageContext: Represents the context of the JSP page that can be used to access shared data on the page.
An instance of Config:servletconfig that represents the configuration information for the JSP page.
###########################################################################################
Request object (JSP built-in object)
Object getattribute (String name): Gets the property value based on the property name
void SetAttribute (String key, Objectvalue): Setting properties
Enumeration Getattributenames (): Get the names of all the properties
String getcharacterencoding (): Gets the character encoding method
String getServerName (): Gets the server name
This article is from the "Zero Technology Road" blog, please be sure to keep this source http://zerohou.blog.51cto.com/3019528/1615023
Cookie and session