Session Technology_Cookie_Detail

table of Contents

1. Can multiple cookies be sent at one time?

2. How long is the cookie stored in the browser?

3. Can cookies be stored in Chinese?

4. What is the scope of cookie acquisition (sharing issue)?

5. The characteristics and functions of cookies


 

1. Can multiple cookies be sent at one time?

Yes, you can create multiple Cookie objects, and use response to call the addCookie method multiple times to send cookies.

 

2. How long is the cookie stored in the browser?

①By default, when the browser is closed, the cookie data is destroyed

②Persistent storage:

ⅠPositive number: Write the cookie data to a file on the hard disk. Persistent storage. Cookie lifetime.

Ⅱ Negative number: default value

Ⅲ Zero: Delete cookie information

 

3. Can cookies be stored in Chinese?

* Chinese data cannot be stored directly in cookies before tomcat 8

Chinese data needs to be transcoded-generally URL encoding (%E3)

* After tomcat 8, cookies support Chinese data.

However, special characters are still not supported, and URL encoding must be used for storage and URL encoding analysis.

 

4. What is the scope of cookie acquisition (sharing issue)?

①Assuming that multiple web projects are deployed in a tomcat server, can cookies be shared among these web projects?

Ⅰ Cookies cannot be shared by default

ⅡsetPath(String path): Set the range of cookie acquisition. By default, the current virtual directory is set

If you want to share, you can set path to "/"

 

②The problem of cookie sharing between different tomcat servers?

setDomain(String path): If the first-level domain name is set to be the same, then the cookie can be shared between multiple services

setDomain(".baidu.com"), then the cookies in tieba.baidu.com and news.baidu.com can be shared

 

5. The characteristics and functions of cookies

Features: ①Cookie stores data in the client browser

          ②The browser has a limit on the size of a single cookie (4kb) and the total number of cookies under the same domain name

             There are also restrictions (20)

Function: ①Cookies are generally used to store a small amount of less sensitive data

          ②In the case of not logging in, complete the server's identification of the client.

 

 

 

Guess you like

Origin blog.csdn.net/Jason_LH1024/article/details/102845176