Cookies and Session Differences

Source: Internet
Author: User

Session principle:
1, session is saved on the server side, theoretically there is no limit, as long as your memory is large enough 2, the first time the browser accesses the server will create a Session object and return a Jsessionid=id value,
Create a Cookie Object key is a value of Jssionid,value ID, write this cookie back to browser 3, the browser carries the value of the cookie information Jsessionid=id on the second visit to the server, If the session of the Jsessionid has been destroyed,
Then it will re-create a new session and return a new jsessionid. Return to browser 4 via cookie, for a Web project, a browser is a shared session, even if there are two Web projects deployed on the same server, The session for two items is different
For example: You deployed two Web projects on Tomcat, Web1, WEB2, respectively. The session created when you access Web1 on one browser is A1, and the session created when you access WEB2 is A2.
After you visit the WEB1 to use the session or A1, multiple visits WEB2 use session is A2 5, session is based on cookie technology, restart the browser after re-access to the original connection will still create a new session,
Because the cookie disappears after the browser is closed, but the original server session is still there, only wait until the destruction time will be automatically destroyed 6, if the browser has disabled cookies, then each visit will create a new session, But we can rewrite the URL through the server-side program, if the page more connections, will increase the unnecessary workload,
That can force your users to turn on receiving cookies and then allow them to access them. Plain English: When you access the server one time, the server opens up a space in memory, returns the only key that opens the space, and returns the key to the browser.
When you visit the second time, the browser will carry the key to the server side to open the corresponding space, if the space has been destroyed and re-returned to open a new space to return the new key to the browser.

tell me the difference between a cookie and a session?

1, cookies and sessions are session technology, the cookie is run on the client, the session is run on the server side.

2, the cookie has the size limit and the browser in the number of stored cookies also has the limit, the session is no size limit and the server's memory size is related.    3, the cookie has security hidden danger, can attack by intercepting or local file to find your cookie. 4, session is saved on the server side will exist for some time to disappear, if the session too much will increase the pressure on the server.

Cookies and Session Differences

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.