public class Cookie extends Object
A HTTP cookie
| Modifier and Type | Class and Description |
|---|---|
static class |
Cookie.Builder |
| Modifier and Type | Method and Description |
|---|---|
static Cookie.Builder |
cookie(String name,
String value)
Constructs a cookie with the specified name and value.
|
String |
getComment()
The comment describing the purpose of this cookie, or
null if the cookie has no comment. |
String |
getDomain()
The domain name of this Cookie.
|
int |
getMaxAge()
The maximum age in seconds of this Cookie.
|
String |
getName()
The name of the cookie.
|
String |
getPath()
Returns the path on the server to which the browser returns this cookie.
|
String |
getValue()
The value of this Cookie.
|
int |
getVersion()
The version of the protocol this cookie complies with.
|
boolean |
isHttpOnly()
Whether this Cookie has been marked as HttpOnly.
|
boolean |
isSecure()
Returns
true if the browser is sending cookies only over a secure protocol, or false if the browser can send cookies using any protocol. |
String |
toString() |
public static Cookie.Builder cookie(String name, String value)
Constructs a cookie with the specified name and value.
The name must conform to RFC 2109. However, vendors may provide a configuration option that allows cookie names conforming to the original Netscape Cookie Specification to be accepted.
The name of a cookie cannot be changed once the cookie has been created.
The value can be anything the server chooses to send. Its value is probably of interest only to the server.
By default, cookies are created according to the Netscape cookie specification. The version can be changed with the setVersion method.
name - the name of the cookievalue - the value of the cookieCookie.Builderpublic String getName()
The name of the cookie.
cookie(String, String)public String getValue()
The value of this Cookie.
cookie(String, String)public String getPath()
Returns the path on the server to which the browser returns this cookie. The cookie is visible to all subpaths on the server.
String specifying a path that contains a servlet name, for example, /catalogCookie.Builder.setPath(java.lang.String)public String getDomain()
The domain name of this Cookie.
Domain names are formatted according to RFC 2109.
public int getMaxAge()
The maximum age in seconds of this Cookie.
By default, -1 is returned, which indicates that the cookie will persist until browser shutdown.
Cookie.Builder.setMaxAge(int)public String getComment()
The comment describing the purpose of this cookie, or null if the cookie has no comment.
public int getVersion()
The version of the protocol this cookie complies with. Version 1 complies with RFC 2109, and version 0 complies with the original cookie specification drafted by Netscape. Cookies provided by a browser use and identify the browser’s cookie version.
0 if the cookie complies with the original Netscape specification; 1 if the cookie complies with RFC 2109Cookie.Builder.setVersion(int)public boolean isHttpOnly()
Whether this Cookie has been marked as HttpOnly.
true if this Cookie has been marked as HttpOnly, false otherwisepublic boolean isSecure()
Returns true if the browser is sending cookies only over a secure protocol, or false if the browser can send cookies using any protocol.
true if the browser uses a secure protocol, false otherwiseCookie.Builder.setSecure(boolean)