Class Cookie
- java.lang.Object
-
- jodd.http.Cookie
-
public class Cookie extends java.lang.ObjectCookie object. Simple cookie data holder, cookie header parser and generator.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Stringcommentprivate java.lang.Stringdomainprivate java.lang.Stringexpiresprivate booleanhttpOnlyprivate java.lang.IntegermaxAgeprivate java.lang.Stringnameprivate java.lang.Stringpathprivate booleansecureprivate java.lang.Stringvalueprivate java.lang.Integerversion
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringgetComment()Returns the comment describing the purpose of this cookie, ornullif the cookie has no comment.java.lang.StringgetDomain()Returns the domain name set for this cookie.java.lang.StringgetExpires()java.lang.IntegergetMaxAge()Returns the maximum age of the cookie, specified in seconds, By default,-1indicating the cookie will persist until session shutdown.java.lang.StringgetName()Returns the name of the cookie.java.lang.StringgetPath()Returns the path on the server to which the session returns this cookie.java.lang.StringgetValue()Returns the value of the cookie.java.lang.IntegergetVersion()Returns the version of the protocol this cookie complies with.booleanisHttpOnly()booleanisSecure()Returnstrueif the session is sending cookies only over a secure protocol, orfalseif the session can send cookies using any protocol.CookiesetComment(java.lang.String purpose)Specifies a comment that describes a cookie's purpose.CookiesetDomain(java.lang.String pattern)Specifies the domain within which this cookie should be presented.CookiesetExpires(java.lang.String expires)CookiesetHttpOnly(boolean httpOnly)CookiesetMaxAge(int expiry)Sets the maximum age of the cookie in seconds.private voidsetName(java.lang.String name)Sets the cookie name and checks for validity.CookiesetPath(java.lang.String uri)Specifies a path for the cookie to which the client should return the cookie.CookiesetSecure(boolean flag)Indicates to the session whether the cookie should only be sent using a secure protocol, such as HTTPS or SSL.CookiesetValue(java.lang.String newValue)Assigns a new value to a cookie after the cookie is created.CookiesetVersion(int version)Sets the version of the cookie protocol this cookie complies with.java.lang.StringtoString()
-
-
-
Field Detail
-
name
private java.lang.String name
-
value
private java.lang.String value
-
comment
private java.lang.String comment
-
domain
private java.lang.String domain
-
maxAge
private java.lang.Integer maxAge
-
expires
private java.lang.String expires
-
path
private java.lang.String path
-
secure
private boolean secure
-
version
private java.lang.Integer version
-
httpOnly
private boolean httpOnly
-
-
Constructor Detail
-
Cookie
public Cookie(java.lang.String name, java.lang.String value)Creates cookie with specified name and 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.
-
Cookie
public Cookie(java.lang.String cookie)
Parses cookie data from given user-agent string.
-
-
Method Detail
-
setName
private void setName(java.lang.String name)
Sets the cookie name and checks for validity.
-
getComment
public java.lang.String getComment()
Returns the comment describing the purpose of this cookie, ornullif the cookie has no comment.
-
setComment
public Cookie setComment(java.lang.String purpose)
Specifies a comment that describes a cookie's purpose. The comment is useful if the session presents the cookie to the user.
-
getDomain
public java.lang.String getDomain()
Returns the domain name set for this cookie. The form of the domain name is set by RFC 2109.
-
setDomain
public Cookie setDomain(java.lang.String pattern)
Specifies the domain within which this cookie should be presented.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 nota.b.foo.com). By default, cookies are only returned to the server that sent them.
-
getMaxAge
public java.lang.Integer getMaxAge()
Returns the maximum age of the cookie, specified in seconds, By default,-1indicating the cookie will persist until session shutdown.
-
setMaxAge
public Cookie setMaxAge(int expiry)
Sets the maximum age of the cookie in seconds.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 session exits. A zero value causes the cookie to be deleted.
-
getPath
public java.lang.String getPath()
Returns the path on the server to which the session returns this cookie. The cookie is visible to all subpaths on the server.
-
setPath
public Cookie setPath(java.lang.String uri)
Specifies a path for the cookie to which the client should return the cookie.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.
-
isSecure
public boolean isSecure()
Returnstrueif the session is sending cookies only over a secure protocol, orfalseif the session can send cookies using any protocol.
-
setSecure
public Cookie setSecure(boolean flag)
Indicates to the session whether the cookie should only be sent using a secure protocol, such as HTTPS or SSL.
-
getName
public java.lang.String getName()
Returns the name of the cookie. The name cannot be changed after creation.
-
getValue
public java.lang.String getValue()
Returns the value of the cookie.
-
setValue
public Cookie setValue(java.lang.String newValue)
Assigns a new value to a cookie after the cookie is created. If you use a binary value, you may want to use BASE64 encoding.
-
getVersion
public java.lang.Integer getVersion()
Returns 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 session use and identify the session's cookie version.
-
setVersion
public Cookie setVersion(int version)
Sets the version of the cookie protocol this cookie complies with. Version 0 complies with the original Netscape cookie specification. Version 1 complies with RFC 2109.
-
isHttpOnly
public boolean isHttpOnly()
-
setHttpOnly
public Cookie setHttpOnly(boolean httpOnly)
-
getExpires
public java.lang.String getExpires()
-
setExpires
public Cookie setExpires(java.lang.String expires)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-