在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);
}
}