Use request. getcontextpath () to set the Cookie Path

Source: Internet
Author: User
Tags set cookie

A problem occurred during the project today:

A project needs to log on automatically. The background implements writing the user name and password to the cookie. The local test is successful, but a problem occurs when the server is deployed. You can check the automatic logon option under ie. When you log on again, you cannot obtain the set cookie value, after research, we found that the difference between local and server access is that there is no project name, that is, IP + port access for server access. After careful research, we found the solution.


When we set cookies in the background

Cookie = new cookie (name, value); cookie. setmaxage (cookietimeout); cookie. setpath (request. getcontextpath (); // the main cause of the C error is response. addcookie (cookie );

In this way, if no project name exists

Request. getcontextpath () or the value is "". In this way, the problem occurs in IE. It is easier to locate the cause and solve the problem. You can directly set path to/to solve the problem.

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.