Writing multiple cookies, only one is stored

T

Tim Strawhacker

Hello --

I've got some code that adds five cookies to an HttpServletResponse by
calling addCookie() on it. I know that the cookies are correct, and that
I'm executing the code to add them. These cookies are sequentially added to
the same HttpServletResponse object in the same doPost() method.

When I call readCookies() on a later HttpServletRequest, I only get one
cookie back -- the last one that was written. I thought at first that maybe
I could write only one cookie per HttpServletResponse, so I was perhaps
overwriting a "slot" in the HttpServletResponse structure, but I know I've
seen examples that wrote multiple cookies together.

Any idea what else could be going wrong?

Thanks,
Tim
 
S

Sudsy

Tim said:
Hello --

I've got some code that adds five cookies to an HttpServletResponse by
calling addCookie() on it. I know that the cookies are correct, and that
I'm executing the code to add them. These cookies are sequentially added to
the same HttpServletResponse object in the same doPost() method.

When I call readCookies() on a later HttpServletRequest, I only get one
cookie back -- the last one that was written. I thought at first that maybe
I could write only one cookie per HttpServletResponse, so I was perhaps
overwriting a "slot" in the HttpServletResponse structure, but I know I've
seen examples that wrote multiple cookies together.

Any idea what else could be going wrong?

Thanks,
Tim

And naturally you're using a different name for each cookie, right?
 
S

Sudsy

Tim said:
Yup. I'm doing the addCookie() call in a loop. Here's my code:
Thanks for looking at it -- Tim

Your code looks fine, almost identical to what I was using for some
testing. Only snag is that my implementation works exactly as
expected. There must be something else awry in your setup. Is there
any unusual handling of pages, e.g. forwarding vs redirecting?
What is the server environment?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top