cookie and session learning the basics

First, the simple use of session

session is a server-side technology, you can create a session object exclusive to each user's browser to the server at runtime.
the session using the steps:

Gets the session object
using session to store data
using a data acquisition session
Note the difference when the session cookie in use, cookie Cookie is the object, while session is HttpSession object; cookie objects created by themselves, while the session object is to obtain the object (request.getSession () ), rather than create HttpSession object itself.

Here is a simple case of session, SessionTest1 store data, SessionTest2 get the data.

SessionTest1:

SessionTest2:

Two, session of the principle of use

session is different from the cookie, when a user first accesses the server, the server creates exclusive session object for the user, and then will return to the object id session cookie form to the client. JSESSIONID have a special attribute this situation cookie to store the id session.
Thus, when the case where the user holds the current browser to go to access the server, depending on the value of JSESSIONID pass over the cookie brought it to find its exclusive session, and then to complete the corresponding session.
Thus, session implementation relies on cookie.

Guess you like

Origin www.cnblogs.com/GX1234/p/12082627.html