1.cookie

Save location: client

Usage:

If no expiration time is set, the cookie is stored in the browser’s memory and its life cycle ends when the browser closes. Session cookie for short. If the expiration time is set, the cookie is saved on the hard disk and still exists after closing the browser until it expires.

2.session

Save location: server

Usage: Session is mainly used with COkie at present


Login case (cookie and session combined)

The user logs in to the system from the client

As can be seen from the above figure, every time a request is sent to the background, a cookie is carried in the header of the request to the background, and the JSESSIONID in the cookie is used to distinguish which user performs the operation in the server. Because the stored Cookie is a session Cookie, the Cookie remains valid as long as the entire browser is not closed. The server generates a new JSESSIONID and returns it to the client when no session cookie is displayed and the login page is displayed.


3. LocalStorage

Storage location: client

Life cycle:

The life cycle of localStorage is permanent, and the data in localStorage does not disappear after the page or browser is closed. LocalStorage data will never disappear unless it is actively deleted.

4. SessionStorage

Storage location: client

Life cycle:

The sessionStorage lifetime is valid only for the current session. SessionStorage introduces the concept of a “browser window.” sessionStorage is data that is always present in the same window. As long as the browser window is not closed, the data remains even if the page is refreshed or another page is entered. However, sessionStorage is destroyed when the browser window is closed. At the same time independently open the same window the same page, sessionStorage is not the same.

The last

  • Like to remember to point a star. Encourage once, thank you!
  • Qq group no. 424072183