我无法检索cookie maxage它总是返回-1
创建cookie:
Cookie securityCookie = new Cookie("sec", "somevalue");
securityCookie.setMaxAge(EXPIRATION_TIME);
Run Code Online (Sandbox Code Playgroud)
检索cookie:
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for(int i=0; i<cookies.length; i++) {
Cookie cookie = cookies[i];
if ("sec".equals(cookie.getName())){
int age = cookie.getMaxAge();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我总是年龄= -1
当我检查firefox cookie到期时,我看到奇怪的日期.
谢谢
小智 1
API 表示 -1 表示直到浏览器运行为止:
返回 cookie 的最长期限,以秒为单位指定,默认情况下,-1 表示 cookie 将持续存在,直到浏览器关闭
EXPIRATION_TIME 常量的值是多少?
| 归档时间: |
|
| 查看次数: |
4952 次 |
| 最近记录: |