On Tue, 27 Aug 2002, Michael Remijan wrote:
> I was able to trace the source of the problem. When I add the
> cookie I call setPath("/"); because I want the cookie visible across
> multiple webapps. However, when I get the cookie out of the
> response by calling getCookies(), the value of getPath() = null! So
> it's like the path information disappeared or isn't being
> reconstructed correctly! So after I get the cookie from the
> request, I call setPath("/") again and call setMaxAge(0), readd it
> to the response by calling addCookie(c) and with that the cookie was
> sucessfully deleted! Not having the "/" path persisting really
> through me. I didn't think of it because it seemed like such an
> obvious thing that tomcat would handle.
Ah, time to get a copy of Jason Hunter's O'Reilly Servlets book. On
page 209:
[referring to cookies]
The get methods are rarely used, however, because when a cookie is
sent to the server, it contains only it's name, value, and version.
If you set an attribute on a cookie received from the client, you
must add it to the response for the change to take effect, and you
should take care that all attributes except name, value, and version
are reset on the cookie as well.
Note that this is not a Tomcat-specific issue, it's the way cookies
work. It's the browser that uses the path information, not the
server, so there's no need to include it with the cookie. Browsers
use it (among other things) to decide whether to send the cookie to a
server on a particular request (based on the URL). (We just ran into
a semi-serious conflict on our site with the way cookie path
information is handled, so I learned a lot about it :-).
> -----Original Message-----
> From: Milt Epstein [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, August 27, 2002 3:42 PM
> To: Tomcat Users List
> Subject: Re: how to delete a cookie?????
>
>
> On Tue, 27 Aug 2002, Michael Remijan wrote:
>
> > ...
> >
> > I'm testing the use of cookies by basically setting up a jsp page in
> > two different contexts and flipping back and forth between them.
> > I've tried to delete the cookie by calling setMaxAge() with -1, 0,
> > and 1 but i've not been able to been able to successfully delete the
> > cookie, i.e when i flip to the other context i get my "found cookie"
> > message instead of the "cookie missing, adding a new one" message.
> > Anyone been able to successfully delete a cookie?
>
> You don't specify fully what you're doing to delete the cookie.
> Remember, after you set up the cookie (BTW, max age of 0 should delete
> it), you need to add the cookie to the response. Changing the cookie
> in the request alone and/or not adding it to the response won't do
> anything.
>
Milt Epstein
Research Programmer
Systems and Technology Services (STS)
Campus Information Technologies and Educational Services (CITES)
University of Illinois at Urbana-Champaign (UIUC)
[EMAIL PROTECTED]
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>