我已在Cookie中使用此代码添加和删除
deleted code:
String profileScore=null;
Cookie cookiesScore =new Cookie("profileScore","");
cookiesScore.setValue("");
cookiesScore.setMaxAge(0);
response.addCookie(cookiesScore);
但未正确删除请帮我举一个例子
答案 0 :(得分:0)
如果使用javascript
,请尝试此操作创建一个Cookie:
call a this method at login:
function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}
删除Cookie:
call a this method at logout:
function deleteCookies() {
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";
}
}