Java HttpCookie getName() 方法

2025年3月22日 | 阅读1分钟

Java HttpCookie 类的 getName() 方法用于返回 cookie 的名称。一旦 cookie 被创建,其名称将无法被更改。

语法

参数

不适用。

返回

上述方法用于返回一个指定 cookie 名称的 String。

示例 1

输出

The name of the cookie is given as: Student

示例 2

输出

The name of the first cookie is given as: Student1
The name of the second cookie is given as: Student2

示例 3

输出

Exception in thread "main" java.lang.IllegalArgumentException: Illegal cookie name
	at java.net.HttpCookie.(Unknown Source)
	at java.net.HttpCookie.(Unknown Source)
	at javatpoint.JavaHttpCookieGetNameExample3.main(JavaHttpCookieGetNameExample3.java:7)
下一主题getPath() 方法