Java HttpCookie getMaxAge() 方法

2025 年 3 月 22 日 | 阅读需 2 分钟

Java HttpCookie 类的 getMaxAge() 方法用于返回 cookie 在秒为单位的最大生存时间。默认情况下,-1 表示该 cookie 在浏览器关闭之前一直有效。

语法

参数

不适用。

返回

上述方法用于返回一个整数,该整数指定 cookie 的最大生存时间(以秒为单位)。

示例 1

输出

The maximum age of the cookie is given as: 1700

示例 2

输出

The maximum age of the first cookie is given as: 2000
The maximum age of the second cookie is given as: 1000

示例 3

输出

The maximum age of the cookie is given as: -1 
下一主题getName() 方法