getMaxAge « Cookie « JSP-Servlet Q&A





1. Cookie getMaxAge    stackoverflow.com

Hello I can't retrieve cookie maxage it always returns -1 Creating cookie:

Cookie securityCookie = new Cookie("sec", "somevalue");
securityCookie.setMaxAge(EXPIRATION_TIME);
Retrieve cookie:
Cookie[] cookies = request.getCookies();
if (cookies != null) {
    for(int i=0; i<cookies.length; i++) {
 ...

2. why cookie.getMaxAge() = -1?    stackoverflow.com

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 ...