은이 같은 시험을 가지고왜 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 사용)
cookie.setMaxAge (60 * 60); 값을 설정했습니다 ... – user340017