aspose file tools*
The moose likes Servlets and the fly likes Deleting non-persistent Cookie Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Deleting non-persistent Cookie" Watch "Deleting non-persistent Cookie" New topic
Author

Deleting non-persistent Cookie

Grant Morris
Greenhorn

Joined: Aug 08, 2001
Posts: 8
According to http://java.sun.com/j2ee/sdk_1.3/techdocs/api/index.html the Cookie object has this to say about the setMaxAge() method...

setMaxAge
public void setMaxAge(int expiry)Sets the maximum age of the cookie in seconds.
A positive value indicates that the cookie will expire after that many seconds have passed. Note that the value is the maximum age when the cookie will expire, not the cookie's current age.

A negative value means that the cookie is not stored persistently and will be deleted when the Web browser exits. A zero value causes the cookie to be deleted.

Parameters:
expiry - an integer specifying the maximum age of the cookie in seconds; if negative, means the cookie is not stored; if zero, deletes the cookie
See Also:
getMaxAge()
--------------------------------

Does this mean that I can delete a non-persistent cookie using something like:

myCookie.setMaxAge(0);
response.addCookie(myCookie);

? Or do I have to do something else to delete a cookie that is not stored persistently? My goal, btw, is to delete a cookie that is not stored persistently without closing the browser.

Thanks,
Grant
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

Moving to the Servlets forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ajith Anand
Ranch Hand

Joined: Aug 30, 2004
Posts: 40
Originally posted by Grant Morris:

Does this mean that I can delete a non-persistent cookie using something like:

myCookie.setMaxAge(0);
response.addCookie(myCookie);

? Or do I have to do something else to delete a cookie that is not stored persistently? My goal, btw, is to delete a cookie that is not stored persistently without closing the browser.

Thanks,
Grant


Hi Grant,

Did you say
to delete a cookie that is stored persistently without closing the browser ?[/QUOTE because there is a mismatch somewhere when you say to delete a cookie that is not stored persistently. There is nothing left for you to delete if it is not stored persistently , right ?

With every


a cookie is persisted.

In a non-persistent case, you would not have anything to delete right ?

When you say

to make a cookie non-persistent. Nothing is set on the client and you have nothing to delete either.


You are right if this is what you meant : to remove "persistent" cookies you may do


You are also right, in that if you set
it lasts only for a browser session. But even in this case the cookie is still persisted.


Ajith And


LXI Technologies P Ltd
[url]www.lxisoft.com[/url]
Grant Morris
Greenhorn

Joined: Aug 08, 2001
Posts: 8
This is a bit confusing, but let's say I create a cookie like this:



Now, suppose a little later on, I want to get rid of the above cookie without exiting the browser. Can I do this?



Thanks,
Grant
[ October 19, 2004: Message edited by: Grant Morris ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Deleting non-persistent Cookie
 
Similar Threads
problem in cookie
Cookie
cookie vs session
Cookie lifetime
expire cookie