A servlet writes a cookie that cannot be read after forwarding

Source: Internet
Author: User
Tags send cookies

I write a cookie in a servlet and then read it to the other servlet, but I can't read the last cookie but read the previous cookie. How can i solve it?

Answer:

The customer sends the request, at which time the current cookie is carried

You send cookies, the data has gone to the client, and when it does not affect the first step sent over the cookie

When you read, you use forwarding, and the cookie at this point is the cookie you requested before you sent the cookie.

The customer will send a new cookie again at the next request

The workaround has 2

1 Local record cookies to request or session, not completely dependent on cookies

2 Do not use forward forwarding, the use of the dispatcher of the redirect on it, this is to return the client, the client will make the request again.

Recommend the second kind, simple and effective

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.