public class Cookie
extends java.lang.Object
| Modifier | Constructor and Description |
|---|---|
protected |
Cookie(java.lang.String cookie)
Parses cookie data from given user-agent string.
|
protected |
Cookie(java.lang.String name,
java.lang.String value)
Creates cookie with specified name and value.
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
comment()
Returns the comment describing the purpose of this cookie, or
null if the cookie has no comment. |
Cookie |
comment(java.lang.String comment)
Specifies a comment that describes a cookie's purpose.
|
static Cookie |
cookie(java.lang.String cookie)
Create a new cookie.
|
static Cookie |
cookie(java.lang.String name,
java.lang.String value)
Create a new cookie.
|
java.lang.String |
domain()
Returns the domain name set for this cookie.
|
Cookie |
domain(java.lang.String domain)
Specifies the domain within which this cookie should be presented.
|
java.lang.String |
encode()
Encode the cookie to a string.
|
java.lang.String |
expires()
Gets expires date.
|
Cookie |
expires(java.lang.String expires)
Sets expires date.
|
boolean |
httpOnly()
If this cookie is HTTP only.
|
Cookie |
httpOnly(boolean httpOnly)
Determines if this cookie is HTTP only.
|
java.lang.Long |
maxAge()
Returns the maximum age of the cookie, specified in seconds,
By default,
-1 indicating the cookie will persist
until browser shutdown. |
Cookie |
maxAge(java.lang.Long maxAge)
Sets the maximum age of the cookie in seconds.
|
java.lang.String |
name()
Returns the name of the cookie.
|
Cookie |
name(java.lang.String name)
Sets the cookie name and checks for validity.
|
java.lang.String |
path()
Returns the path on the server
to which the browser returns this cookie.
|
Cookie |
path(java.lang.String path)
Specifies a path for the cookie
to which the client should return the cookie.
|
boolean |
secure()
Returns
true if the browser is sending cookies
only over a secure protocol, or false if the
browser can send cookies using any protocol. |
Cookie |
secure(boolean secure)
Indicates to the browser whether the cookie should only be sent
using a secure protocol, such as HTTPS or SSL.
|
java.lang.String |
value()
Returns the value of the cookie.
|
Cookie |
value(java.lang.String value)
Assigns a new value to a cookie after the cookie is created.
|
java.lang.Integer |
version()
Returns the version of the protocol this cookie complies
with.
|
Cookie |
version(java.lang.Integer version)
Sets the version of the cookie protocol this cookie complies
with.
|
protected Cookie(java.lang.String cookie)
protected Cookie(java.lang.String name,
java.lang.String value)
The name must conform to RFC 2109. That means it can contain only ASCII alphanumeric characters and cannot contain commas, semicolons, or white space or begin with a $ character.
The value can be anything the server chooses to send.
public static Cookie cookie(java.lang.String cookie)
cookie - The encoded string of the cookie.public static Cookie cookie(java.lang.String name, java.lang.String value)
name - The name of the cookie.value - The cookie value.public java.lang.String comment()
null if the cookie has no comment.public Cookie comment(java.lang.String comment)
public java.lang.String domain()
public Cookie domain(java.lang.String domain)
The form of the domain name is specified by RFC 2109. A domain
name begins with a dot (.foo.com) and means that
the cookie is visible to servers in a specified Domain Name System
(DNS) zone (for example, www.foo.com, but not
a.b.foo.com). By default, cookies are only returned
to the server that sent them.
public java.lang.String encode()
public java.lang.String expires()
public Cookie expires(java.lang.String expires)
public boolean httpOnly()
public Cookie httpOnly(boolean httpOnly)
httpOnly - True if the cookie is HTTP only, otherwise false.public java.lang.Long maxAge()
-1 indicating the cookie will persist
until browser shutdown.public Cookie maxAge(java.lang.Long maxAge)
A positive value indicates that the cookie will expire after that many seconds have passed. Note that the value is the maximum age when the cookie will expire, not the cookie's current age.
A negative value means that the cookie is not stored persistently and will be deleted when the Web browser exits. A zero value causes the cookie to be deleted.
public java.lang.String name()
public Cookie name(java.lang.String name)
public java.lang.String path()
public Cookie path(java.lang.String path)
The cookie is visible to all the pages in the directory you specify, and all the pages in that directory's subdirectories. A cookie's path must include the servlet that set the cookie, for example, /catalog, which makes the cookie visible to all directories on the server under /catalog.
Consult RFC 2109 (available on the Internet) for more information on setting path names for cookies.
public boolean secure()
true if the browser is sending cookies
only over a secure protocol, or false if the
browser can send cookies using any protocol.public Cookie secure(boolean secure)
public java.lang.String value()
public Cookie value(java.lang.String value)
public java.lang.Integer version()
public Cookie version(java.lang.Integer version)