• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Redirect after addCookie

 
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 )
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bauke, Thanks for you good explanation.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome.
 
I think she's lovely. It's this tiny ad that called her crazy:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic