• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Redirect after addCookie

 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found that the response.addCookie will not work properly, if I use a redirect statement after the addCookie statement.

For an example:

response.addCookie(myCookie);
response.sendRedirect("somewhere.html");


In the above example, the cookie will never store on the browser, unless I remove the sendRedirect statement.


Any solution?
(Please don't tell me to use RequestDispatcher instead )
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using Tomcat or some Tomcat based appserver? Which version? There was a bug related to this in older versions.
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bauke Scholtz:
Are you using Tomcat or some Tomcat based appserver? Which version? There was a bug related to this in older versions.


I'm using Tomcat 5.0
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
https://issues.apache.org/bugzilla/show_bug.cgi?id=248
https://issues.apache.org/bugzilla/show_bug.cgi?id=258

It is not clear to me when they fixed it, but the last response was dated at november 2003, shortly after 5.0 came out for first time, september 2003.

Consider upgrading to at least 5.5. I did a quick test at my Tomcat 6.0.18 and it just works fine.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On the other hand, cookies are domain and path specific. Make sure that you don't redirect to some URL/path outside the scope of the cookie.
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bauke, Thanks for you good explanation.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic