stay Python in Cookie and Session What's the connection ?Cookie and Session What's the difference ? Next, let's take a look at the detailed content introduction , I hope it will help you .
First of all 、 Different access methods
Cookie You can only keep ASCII character string , If access is required Unicode Character or binary data , The requirements are encoded first .Cookie No direct access to Java object , To store slightly more complex information , Application Cookie It's hard .
Session Can access any type of data , Including but not limited to string、integer、list、Map etc. .session China can also keep JavaBean Or anything Java class 、 Object etc. , It's very convenient to use .
second 、 Different privacy policies
Cookie Stored in a client reader , Visible to clients , Some programs on the client may snoop 、 Copy or even modify Cookie The content in . and session Store on the server , Transparent to clients , There is no risk of sensitive information leaking .
Third 、 Different expiry dates
Have used Google Everyone knows , If you've logged in Google, be Google The login information is valid for a long time . Users don't have to log in every time they visit ,Google The login information of the user will be recorded for a long time . To achieve this effect , Application Cookie Would be a better choice . Just set up Cookie The expiration time attribute of is a very large number .
because Session Depends on the name JSESSIONID Of Cookie, and Cookie JSESSIONID The expiration date of is tacit –1, Just shut down the reader Session It will fail. , thus Session Can't complete the result that the information is valid forever .
Fourth 、 Server pressure is different
Session It's on the server side , Each user will generate a Session. If there are many concurrent users , There will be a lot of Session, Consume a lot of memory , thus Google、Baidu、Sina In this way, the website with high concurrent visits , It's impossible to use Session To track customer conversations .
and Cookie It is kept on the client , No server resources . If there are many concurrent users ,Cookie It's a good choice .
The fifth 、 Browsers support different
Cookie It needs the support of client browser . If the client is disabled Cookie, Or not Cookie, Then session tracking will fail . About Wap Application on , The conventional Cookie It won't work .
If the client browser does not support Cookie, Need to use Session as well as URL Address rewrite . What needs to be noted is the use of everything Session programmatic URL To carry out URL Address rewrite , otherwise Session Session tracking will also fail .
The sixth 、 Different support across domains
Cookie Support cross domain access , and Session Cross domain access will not be supported ,Session Only valid in his domain name .