Session mechanism Cookie & Session

table of Contents

What is a conversation

Two techniques for saving sessions

Session


 

What is a conversation

 

The user opens a browser, clicks on many hyperlinks, and accesses multiple web resources until the browser is closed. This process is called a session.

Most websites need to be in a stateful session, that is, after the user logs in, the web page is closed and the account information is saved.

 

 

Two techniques for saving sessions

 

cookie (client technology), session (server technology)

 

 

 

The first time the user logs in to visit the website, the server will give you a cookieId, cookieId and cookie information are saved in the client (browser), the next time the user starts the browser, the user communicates with the server through cookieId, the browser displays the user login information

  • cookie: generally stored in the local C drive user directory appdata
  • One cookie can only save one message;
  • A web site can send multiple cookies to the browser and store up to 20 cookies;
  • Cookie size is limited to 4kb;
  • There are two ways to delete cookies. Without setting the validity period, close the browser and it will automatically become invalid; set the validity period to 0;

Encoding and decoding cookies

URLEncoder.encode("回家","utf-8")
URLDecoder.decode(cookie.getValue(),"UTF-8")

 

 

Session

 

The server will also create a Session object when the user first visits. ( Session information exists in the server, and the sessionId returned by the server will be saved in the browser ). And a Session will monopolize a browser, as long as the browser is not closed, this Session exists.

 

 

 

Published 568 original articles · Like 180 · Visits 180,000+

Guess you like

Origin blog.csdn.net/Delicious_Life/article/details/105542897