Cookie operation

Cookie operation

Introduction: Quickly learn cookie operations and solve cookie problems
The developer school course [Java Interview Difficulties Talk 5: System Architecture and Project Design The first lesson: Cookie problem] study notes, which are closely related to the course, allowing users to quickly learn knowledge.
Course address: https://developer.aliyun.com/learning/course/28/detail/603

【Cookie operation】Cookie problem
1. Does the cookie need to be set after the client's day transfer is completed?
A: For the setting of cookies, there are two modes:
•The automatic setting of WEB service: refers to the first visit to any page in it, whether this page is redirected or not, as long as it is accessed by the user, as long as it is the first visit, the system will automatically set a cookie;
•It is a manual way to set cookies, and most developers will ignore a key issue, which is the path of cookies. By default, it is assumed that in the "pages/back/msg" directory, respond.addCookie (c) is executed in this directory, and the cookies at this time will only exist in this directory.



In this state, you must click to refresh, and you can view the data of a cookie only by clicking refresh, so even if the cookie is set at this time, if the directory is changed, for example: "pages/back", then the cookie cannot be obtained.
Because the paths are different, it is necessary to set the path when setting the cookie. If you want to save it, in addition to setting the time, you also need to set the path, and the path is set to the root directory.
Get method for root directory: " request.getContextPayh ()".

2. If there is a server jump after the response.setCookie is used , will it not be possible to obtain the cookie after the server jump?
A: It can be obtained. The key question is whether the set path has "set/pass". If so, it can be obtained. This is a very critical issue.

3. It cannot be displayed on the display page, but you can find the cookie after refreshing it.
Answer: Cookie will definitely jump, but if you use the server to jump, you will definitely not be able to get it for the first time. The premise is to ensure that the path is correct. After the jump, you need to manually refresh before you can get the data.



Copyright statement: The content of this article is contributed by Alibaba Cloud's real-name registered users. The copyright belongs to the original author. The Alibaba Cloud developer community does not own the copyright and does not assume the corresponding legal responsibility. For specific rules, please refer to the " Alibaba Cloud Developer Community User Service Agreement " and " Alibaba Cloud Developer Community Intellectual Property Protection Guidelines ". If you find any content suspected of plagiarism in this community, fill out the infringement complaint form to report it. Once verified, this community will delete the allegedly infringing content immediately.

Related Articles

Explore More Special Offers

  1. Short Message Service(SMS) & Mail Service

    50,000 email package starts as low as USD 1.99, 120 short messages start at only USD 1.00