Home  >>  JavaServer Pages (JSP)  >>  

How can I set a cookie and delete a cookie from with in a JSP page?

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

<%

//creating a cookie

Cookie mycookie = new Cookie("Name","aValue");

response.addCookie(mycookie);

//delete a cookie

Cookie killMyCookie = new Cookie("mycookie", null);

killMyCookie.setMaxAge(0);

killMyCookie.setPath("/");

response.addCookie(killMyCookie);

%>

JavaServer Pages (JSP)