A comparison of cookies and sessions based on Java _java

Source: Internet
Author: User
Tags sessions

Comparison of Cookie and session

First, for cookies:

①cookie is created on the server side

②cookie saved in Browser end

The ③cookie lifecycle can be set by Cookie.setmaxage (2000), and if no setmaxage is set,

The lifetime of the cookie dies when the browser closes

④cookie can be shared by multiple browsers of the same type to think of cookies as a table

Comparison:

Location of ①:

Cookies exist in the client, temporary folder

Session: exists in the server's memory, a session domain object for a user browser service

② Security

Cookies are stored in plaintext in the client, security is low, can be encrypted by a cryptographic algorithm to store

Session is stored in the server's memory, so security is good

③ Network Transmission Volume

Cookies will pass messages to the server

Session itself is stored on the server and there is no traffic

④ lifecycle (take 20 minutes as an example)

(1) The life cycle of the cookie is cumulative, starting at the time of creation, the timer is 20 minutes later, the cookie lifecycle is over,

(2) The life cycle of the session is the interval, from the time of creation, start the timing, such as in 20 minutes, no access session, then the session lifecycle is destroyed

However, if the session is accessed within 20 minutes (for example, at 19 minutes), the session life cycle is recalculated

(3) The closing opportunity causes the session life cycle to end, but has no effect on the cookie

⑤ Access Scope

Session is exclusive to a user's browser

Cookies are shared by multiple user browsers

The method that causes the session to fail:

1. Turn off Tomcat

2.reload Web Applications

3.session Time to

4 Invalidate session

This is based on the Java cookie and session of the comparison is small series to share all the content, hope to give you a reference, but also hope that we support the cloud habitat community.

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: info-contact@alibabacloud.com 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.