Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Deleting non-persistent Cookie

 
Grant Morris
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the Servlets forum.
 
Ajith Anand
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Grant Morris
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic