A negative value means that the cookie is not stored persistently and
will be deleted when the Web browser exits. A zero value causes the cookie
to be deleted.
另一个是
Iterate all cookies in servlet/Scriptlet and set all Cookies Value NULL .
更新:我不熟悉JSP,所以我使用PHP和Javascript为例,假设你没有HttpOnly属性在你的cookie。 I use this PHP code to set cookie, you can upload this PHP script to your web server, www.yourserver.com/setcookie.php
<?php
setcookie('name', 'li');
?>
And I use this HTML file to clear your cookies, once again, upload this HTML file to your web server, www.yourserver.com/clearcookie.html
<script>
function deleteAllCookies() {
var cookies = document.cookie.split(";");
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i];
var eqPos = cookie.indexOf("=");
var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
}
}
deleteAllCookies();
</script>
3条答案
按热度按时间j8ag8udp1#
如果您不想删除,另一种选择是将它们存储为持久cookie
MaxAge为-1表示您希望Cookie在会话期间保持不变。您希望将MaxAge设置为0。
另一个是
还有一个
sf6xfgos2#
引用RFC 2109,只需在HTTP响应中使用Set-Cookie头,并将希望清除的cookie设置为空值。
更新:我不熟悉JSP,所以我使用PHP和Javascript为例,假设你没有HttpOnly属性在你的cookie。
I use this PHP code to set cookie, you can upload this PHP script to your web server, www.yourserver.com/setcookie.php
And I use this HTML file to clear your cookies, once again, upload this HTML file to your web server, www.yourserver.com/clearcookie.html
ioekq8ef3#
使用以下代码。