操作cookie的困惑
wfdmd 2004-09-15 02:30:14 写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