Comparison of cookies and sessions

First, for cookies:

① The cookie is created on the server

② The cookie is saved on the browser

③ Cookie life cycle can be set by cookie.setmaxage (2000);if setmaxage is not set,

The life cycle of the cookie when the browser is closed,Perish

④Cookies can be shared by multiple browsers of the same type. Think of cookies as a table.


① Existing location:

cookie exists on the client,In the temporary folder

session:exists in the server's memory,A session domain object serves a user's browser

② Security

Cookies are stored on the client in plain text.Low security,Can be stored after being encrypted by an encryption algorithm

The session is stored in the server's memory,So good security

③ Network transmission

The cookie passes the message to the server

The session itself is stored on the server,No traffic

④ Life cycle (take 20 minutes as an example)

(1) The life cycle of a cookie is cumulative,From when it was created,Start timing,After 20 minutes, the cookie life cycle ends,

(2) The life cycle of the session is interval,From when it was created,If the timer starts at 20 minutes and no session is accessed, then the session life cycle is destroyed

However, if the session is accessed within 20 minutes (such as at the 19th minute), the session life cycle will be recalculated

(3) shutdown will cause the end of the session life cycle,But has no effect on cookies

⑤Access range

session exclusive for a user's browser

Cookies are shared by multiple user browsers

Methods to invalidate the session:

1.Close tomcat

2.reload web application

3.session time is up

4 invalidate session

  • Previous Upload file using JQuery plugin ajaxFileUpload in Aspnet MVC
  • Next Detailed Bitmap of Android picture cache (1)