Author
Redirect after addCookie
Treimin Clark
Ranch Hand
Joined: Nov 12, 2008
Posts: 757
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
Joined: Oct 08, 2006
Posts: 2458
posted Dec 18, 2008 16:07:00
0
Are you using Tomcat or some Tomcat based appserver? Which version? There was a bug related to this in older versions.
Code depot of a Java EE / JSF developer | JSF / Eclipse / Tomcat kickoff tutorial | DAO kickoff tutorial | I ♥ Unicode
Treimin Clark
Ranch Hand
Joined: Nov 12, 2008
Posts: 757
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
Joined: Oct 08, 2006
Posts: 2458
posted Dec 18, 2008 17:33:00
0
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
Joined: Oct 08, 2006
Posts: 2458
posted Dec 18, 2008 17:36:00
0
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
Joined: Nov 12, 2008
Posts: 757
Bauke, Thanks for you good explanation.
Bauke Scholtz
Ranch Hand
Joined: Oct 08, 2006
Posts: 2458
posted Dec 19, 2008 06:27:00
0
You're welcome.
subject: Redirect after addCookie