why cookie.getMaxAge() = -1?

Posted by wavelet on Stack Overflow See other posts from Stack Overflow or by wavelet
Published on 2010-06-18T02:12:51Z Indexed on 2010/06/18 2:43 UTC
Read the original article Hit count: 413

Filed under:
|
|

i have a test like this :

cookie.jsp:

<html>  
<head>
</head>  
<body>  
<%  
String cookieName="SNS";  
Cookie cookie=new Cookie(cookieName, "maxAgeTest");  
cookie.setMaxAge(60*60);  
response.addCookie(cookie);  
%>  
</body>  
</html>

and read.jsp is :

<html>  
<head>
</head>  
<body>  
<table border=1>  
<tr><td>Name</td><td>value</td></tr>  
<%  
Cookie cookies[]=request.getCookies();  
Cookie sCookie=null;  
String svalue=null;  
String sname=null;  
int sage ; 
for(int i=0;i<cookies.length;i++)  
{  
sCookie=cookies[i];  
svalue=sCookie.getValue();  
sname=sCookie.getName();  
sage=sCookie.getMaxAge();
%>  
<tr><td><%=sname%></td><td><%=svalue%></td><td><%=sage%></td></tr>  
<%  
}  
%>  
</table>
</body>  
</html> 

but the result is :

Name value maxAge

JSESSIONID DB3561A47B37FCA8CA25EA04B80A26C7 -1

SNS maxAgeTest -1

why the maxAge is -1 ?

and t test IE8,Chrome5,Safari ,the result same

© Stack Overflow or respective owner

Related posts about java

Related posts about jsp