On Sun, 11 Mar 2001, Scott Walter wrote:

> Hi,
> 
> I have a general question concerning cookies with
> Struts.  From page1.jsp I call a Struts action called
> "removecookie.do". The action basically sets a cookie
> max expiration date to zero (to delete the cookie). 
> When the action is completed the request if forwarded
> back to page1.jsp.  
> 
> However the cookie is still available on page1.jsp. 
> If I restart a new browser session the cookie is no
> longer there.
> 
> Is the cookie still there because basically calling
> the struts action and the forwarding to page1.jsp are
> part of the same request?
>

That is correct.  Setting the cookie expiration will not have any effect
on the browser until you actually send a response containing the new
setting (effectively deleting the cookie) -- it will be gone on a
subsequent request.

This is not really specific to Struts -- it's the way cookies work in
servlet based applications.

 
> Has anyone got a solution for this.
>

One option would be to use a <forward> that does a sendRedirect() instead
of a RequestDispatcher.forward().  This would cause the cookie to be
deleted, at the expense of being able to pass request attributes back to
page1.jsp again -- you'd need to use session attributes now.
 
> Scott

Craig McClanahan


Reply via email to