public class Cookie
extends java.lang.Object
Constructor and Description |
---|
Cookie(java.lang.String cookie)
Parses cookie data from given user-agent string.
|
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 |
getComment()
Returns the comment describing the purpose of this cookie, or
null if the cookie has no comment. |
java.lang.String |
getDomain()
Returns the domain name set for this cookie.
|
java.lang.String |
getExpires() |
java.lang.Integer |
getMaxAge()
Returns the maximum age of the cookie, specified in seconds,
By default,
-1 indicating the cookie will persist
until browser shutdown. |
java.lang.String |
getName()
Returns the name of the cookie.
|
java.lang.String |
getPath()
Returns the path on the server
to which the browser returns this cookie.
|
java.lang.String |
getValue()
Returns the value of the cookie.
|
java.lang.Integer |
getVersion()
Returns the version of the protocol this cookie complies
with.
|
boolean |
isHttpOnly() |
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. |
Cookie |
setComment(java.lang.String purpose)
Specifies a comment that describes a cookie's purpose.
|
Cookie |
setDomain(java.lang.String pattern)
Specifies the domain within which this cookie should be presented.
|
Cookie |
setExpires(java.lang.String expires) |
Cookie |
setHttpOnly(boolean httpOnly) |
Cookie |
setMaxAge(int expiry)
Sets the maximum age of the cookie in seconds.
|
Cookie |
setPath(java.lang.String uri)
Specifies a path for the cookie
to which the client should return the cookie.
|
Cookie |
setSecure(boolean flag)
Indicates to the browser whether the cookie should only be sent
using a secure protocol, such as HTTPS or SSL.
|
Cookie |
setValue(java.lang.String newValue)
Assigns a new value to a cookie after the cookie is created.
|
Cookie |
setVersion(int version)
Sets the version of the cookie protocol this cookie complies
with.
|
java.lang.String |
toString() |
public 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 Cookie(java.lang.String cookie)
public java.lang.String getComment()
null
if the cookie has no comment.public Cookie setComment(java.lang.String purpose)
public java.lang.String getDomain()
public Cookie setDomain(java.lang.String pattern)
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.Integer getMaxAge()
-1
indicating the cookie will persist
until browser shutdown.public Cookie setMaxAge(int expiry)
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 getPath()
public Cookie setPath(java.lang.String uri)
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 isSecure()
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 setSecure(boolean flag)
public java.lang.String getName()
public java.lang.String getValue()
public Cookie setValue(java.lang.String newValue)
public java.lang.Integer getVersion()
public Cookie setVersion(int version)
public boolean isHttpOnly()
public Cookie setHttpOnly(boolean httpOnly)
public java.lang.String getExpires()
public Cookie setExpires(java.lang.String expires)
public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2003-present Jodd Team