6

i have used webservice into my application and want to delete information from cookies that is saved on one state and must be deleted on another state on particular condition given. How can i do so? Thanks

Nikki
  • 3,314
  • 13
  • 36
  • 59

2 Answers2

9

check http://www.ehow.com/how_5169279_remove-cookies-java.html

How can I delete a cookie from within a JSP page?

A cookie, mycookie, can be deleted using the following scriptlet:

<%
     Cookie killMyCookie = new Cookie("mycookie", null);
     killMyCookie.setMaxAge(0);
     killMyCookie.setPath("/");
     response.addCookie(killMyCookie);
%>

How do I delete a cookie set by a servlet?

Get the cookie from the request object and use setMaxAge(0) and then add the cookie to the response object.

http://www.hccp.org/java-net-cookie-how-to.html

Singleton
  • 3,701
  • 3
  • 24
  • 37
  • I want to delete a particular cookie information not whole. Does this code will work for that also – Nikki Dec 02 '10 at 06:40
1

You can delete or unset cookies in JSP by setting setMaxAge() for the cookie to zero. For example:

Cookie[] cookies = request.getCookies();
cookies[0].setMaxAge(0);
response.addCookie(cookies[0]);

Here we collect all cookies and delete the first cookie by setting its age to zero.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Codemaker2015
  • 12,190
  • 6
  • 97
  • 81