How to delete a cookie in a JSP page?

Answered

How to delete a cookie in a JSP page?

Ninja Asked on 18th September 2018 in Jsp.
Add Comment
1 Answer(s)
Best answer

Cookie can be deleted by setting setMaxAge(0) on the cookie object. A cookie, democookie, can be deleted using the following scriptlet:

<%
 Cookie delCookie = new Cookie("democookie", null);
 delCookie.setMaxAge(0);
 delCookie.setPath("/");
 response.addCookie(delCookie);
%>
Ninja Answered on 18th September 2018.
Add Comment