2010-06-18 2 views
1

은이 같은 시험을 가지고왜 cookie.getMaxAge() = -1입니까?

cookie.jsp :

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

하지만 결과이다 :

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

및 read.jsp이다

이름 값 MAXAGE

JSESSIONID DB3561A47B37FCA8CA25EA04B80A26C7 -1

SNS maxAgeTest -1

maxAge가 -1 인 이유는 무엇입니까?

와 t 테스트 IE8, Chrome5, 사파리, 당신이 MaxAge 값을 설정하지 않았기 때문에 (setMaxAge 사용)

답변

2

같은 결과. 그래서 기본값 (-1)이됩니다. 즉, 쿠키가 브라우저 종료까지 유지됩니다.

+1

cookie.setMaxAge (60 * 60); 값을 설정했습니다 ... – user340017

4

당신은 그것을 얻을 수 없습니다. 브라우저는 쿠키의 이름과 값만 돌려주고 다른 정보는 보내지 않습니다.