This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Programmatically removing a cookie Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Programmatically removing a cookie" Watch "Programmatically removing a cookie" New topic
Author

Programmatically removing a cookie

MalanS Subramanian
Greenhorn

Joined: Jul 09, 2005
Posts: 8
Hi Ranchers,
Is it possible to programatically remove a cookie? I tried looking in Servlet API and couldnt find any...

Thanks in advance
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi Malan. Can you please tell, in which situations this behaviour is needed? Thankyou.
MalanS Subramanian
Greenhorn

Joined: Jul 09, 2005
Posts: 8
Hi Chinmaya,
I dont have any situations as such in my mind, but was just wondering whether this is doable.
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi Malan. Thanks for the reply. There is no remove method available in Servlet api. If we want to restrict particular client we can follow better alternatives, like filtering. As far my knowledge concerned, this behavior is not needed.
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
It is possible to remove a cookie, you just need a little workaround.

Retrieve the cookie, set MaxAge to 0 and reinsert it.


JDBCSupport - An easy to use, light-weight JDBC framework -
MalanS Subramanian
Greenhorn

Joined: Jul 09, 2005
Posts: 8
Hi Sebastian,
Thanks for the reply... thats a cute lil workaround
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
Apart from being cute, it's pretty much the only way to remove a cookie from the server side,,,
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Programmatically removing a cookie
 
Similar Threads
Famous Quotes
How to set JSESSIONID's maxAge?
WA #1.....word association
Not able to post
Cookies using Jsp