You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Scott Walter <tx...@yahoo.com> on 2001/03/11 20:42:48 UTC

Struts and Cookies

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?

Has anyone got a solution for this.

=====
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Scott
May the Force be with you!

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - Buy the things you want at great prices.
http://auctions.yahoo.com/

Re: Struts and Cookies

Posted by "Craig R. McClanahan" <cr...@apache.org>.

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