//JS操作cookies方法!
//写cookies
function setCookie(name,value)
{
var Days = 30;
var exp = new Date();
exp.setTime(exp.getTime() + Days2460601000);
document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
//读取cookies
function getCookie(name)
{
var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
if(arr=document.cookie.match(reg))
return unescape(arr[2]);
else
return null;
}
后台:
// 获取request里面的cookie cookie里面存值方式也是 键值对的方式
Cookie[] cookie = request.getCookies();
for (int i = 0; i < cookie.length; i++) {
Cookie cook = cookie[i];
if(cook.getName().equalsIgnoreCase("eredg4.login.account")){ //获取键
System.out.println("account:"+cook.getValue().toString()); //获取值
}
}