How can I delete a cookie with JSP?-

Say that I have a cookie called “foo, ” that I set a while ago & I want it to go away. I simply: <% Cookie killCookie = new Cookie(”foo”, null); KillCookie. setPath(”/”); killCookie. setMaxAge(0); response. addCookie(killCookie); %>

In JavaServer Pages (JSP), you can delete a cookie using the HttpServletResponse object. Here’s an example of how you can delete a cookie in JSP:

jsp
<%@ page import="javax.servlet.http.Cookie" %>
<%@ page import="javax.servlet.http.HttpServletResponse" %>
<%
// Get the current response object
HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();

// Create a cookie with the same name as the one you want to delete
Cookie cookieToDelete = new Cookie(“yourCookieName”, “”);

// Set the cookie’s max age to 0, which effectively deletes it
cookieToDelete.setMaxAge(0);

// Add the cookie to the response
response.addCookie(cookieToDelete);
%>

Make sure to replace “yourCookieName” with the actual name of the cookie you want to delete. Setting the max age to 0 essentially instructs the browser to delete the cookie. The next time the browser makes a request to the server, the cookie will no longer be included.

Note: This code should be placed in a JSP file, and it’s executed when the page is requested. Also, keep in mind that cookies are client-side, and this approach relies on the client (browser) to delete the cookie.