• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Deleting non-persistent Cookie

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to the Servlets forum.
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
For my next feat, I will require a volunteer from the audience! Perhaps this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic