操作cookie的困惑

wfdmd wfdmd 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
写cookie成功了。getName(),getValue()都成功了,但是getMaxAge()出了问题:
1.jsp
Cookie cookieuser=new Cookie("user","test");
cookieuser.setMaxAge(3650*24*3600);
response.addCookie(cookieuser);
int age=cookieuser.getMaxAge();
out.println(age);
2.jsp
Cookie [] getCookies=request.getCookies();
for (int i=0; i<getCookies.length; i++)
{
String user=getCookies[i].getName();
String value=getCookies[i].getValue();
int age=getCookies[i].getMaxAge();
out.println("user="+user+" value="+value+" i="+i);
out.println("age="+age+"<br>");

}
为什么1.jsp里取出来的age是正确的数字,但是2.jsp里取出来的age为-1
...全文
评论 6
收藏 已收藏
分享
返回顶部
wfdmd
Web 开发 81,108 成员 341,721 内容