在Java中删除cookie,有以下几种方式:
Cookie cookie = new Cookie("cookieName", "");
cookie.setMaxAge(0);
response.addCookie(cookie);
Cookie cookie = null;
cookie = new Cookie("cookieName", null);
cookie.setMaxAge(0);
response.addCookie(cookie);
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
cookie.setMaxAge(0);
response.addCookie(cookie);
}
}
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
cookie.setMaxAge(0);
}
}