Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can delete information from cookies?

Tags:

java

cookies

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

like image 918
Nikki Avatar asked Dec 02 '10 06:12

Nikki


2 Answers

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

like image 198
Singleton Avatar answered Sep 28 '22 09:09

Singleton


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.

like image 45
Codemaker Avatar answered Sep 28 '22 08:09

Codemaker