cookie 修改不了

偶发现一个cookie问题,本地服务器端修改不了路径属性,直接上代码:

Cookie cd = new Cookie("dddg3ddf34","dddddffff");

cd.setDomain("test.xxx.cn");

cd.setPath("/haha");

cd.setComment("dddfff");

getResponse().addCookie(cd);

页面cookie值:

路径是我请求的action,后台设置path不生效。

再跳次访问同样的连接:cookie修改下value值:

Cookie cd = new Cookie("dddg3ddf34","dddddffff");

cd.setDomain("test.xxx.cn");

cd.setPath("/haha");

cd.setComment("dddfff");

cd.setSecure(true);

getResponse().addCookie(cd);

又会生成一个cookie:

路径又变成根了,咋回事儿?而且后台接受到的所有cookie的path,domain是空值

代码:

Cookie [] ck = getRequest().getCookies();

for(Cookie ek:ck){

System.out.print("Domain->" + ek.getDomain());

System.out.print("\tMaxAge->" + ek.getMaxAge());

System.out.print("\tname->" + ek.getName());

System.out.print("\tpath->" + ek.getPath());

System.out.print("\tSecure->" + ek.getSecure());

System.out.print("\tValue->" + ek.getValue());

System.out.print("\tVersion->" + ek.getVersion());

}

打印结果:

Domain->nullMaxAge->-1name->dddg3ddf34path->null

猜你喜欢

转载自wzpwap123.iteye.com/blog/2055448
今日推荐