remove Cookies from HttpServletRequest - Java Servlet JSP

Java examples for Servlet JSP:Cookie

Description

remove Cookies from HttpServletRequest

Demo Code


import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Main{
    public static void removeCookies(HttpServletRequest request,
            HttpServletResponse response) {
        Cookie[] cookies = request.getCookies();
        for (int i = 0; i < cookies.length; i++) {
            Cookie cookie = cookies[i];//from w ww  .j  av  a 2 s  .c om
            removeCookie(response, cookie.getName());
        }
    }
    public static void removeCookie(HttpServletResponse response,
            String name) {
        Cookie cookie = new Cookie(name, "");
        cookie.setMaxAge(0);
        response.addCookie(cookie);
    }
}

Related Tutorials