Wednesday, January 24, 2007

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

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

<%

//creating a cookie
Cookie mycookie = new Cookie("aName","aValue");
response.addCookie(mycookie);

//delete a cookie
Cookie killMyCookie = new Cookie("mycookie", null);
killMyCookie.setMaxAge(0);
killMyCookie.setPath("/");
response.addCookie(killMyCookie);

%>


SOURCE : www.referjava.com

No comments: