Javatpoint Logo
Javatpoint Logo

Java HttpCookie class

Methods

Method Description
clone() Creates and returns a copy of the given object.
domainMatches(String domain, String host) Checks whether the given host name lies in the domain or not.
equals(Object obj) Tests the equality of two HTTP cookies.
getComment() Returns the comment which describes the purpose of the cookie. Also, returns null if the cookie has no comment.
getCommentURL() Returns the comment URL which describes the purpose of the cookie. Also, returns null if the cookie has no comment URL.
getDiscard() Returns the discard attribute of the cookie.
getDomain() Returns the domain name set for the given cookie.
getMaxAge() Returns the maximum age of the cookie within seconds.
getName() Returns the name of the cookie.
getPath() Returns the path on the server on which the browser returns the cookie.
getPortList() Returns the port list attribute of the cookie.
getSecure() Returns true if sending the cookie is restricted to a secure protocol. Also, returns false if it is sent using any protocol.
getValue() Returns the value of the cookie.
getVersion() Returns the version of the protocol which the cookie compiles with.
hasExpired() Reports whether the HTTP cookie has expired or not.
hasCode() Returns the hash code of the given HTTP cookie.
isHttpOnly() Returns true if the cookie contains HttpOnly attribute.
parse(String header) Constructs cookies from set-cookie or set-cookie2 header string.
setComment(String purpose) Specifies a comment which describes a cookie?s purpose.
setCommentURL(String purpose) Specifies a comment URL which describes a cookie?s purpose.
setDiscard(boolean discard) Specifies whether the user agent can discard the cookie unconditionally or not.
setDomain(String pattern) Specifies the domain within which the cookie can be presented.
setHttpOnly(boolean httpOnly) Indicates whether the cookie can be considered HTTP Only.
setMaxAge(long expiry) Sets the maximum age of the cookie in seconds.
setPath(String uri) Specifies a path for the cookie for which the client can return the cookie.
setPortlist(String ports) Specifies the portlist of the cookie which restricts the port from which cookies can be sent back in a Cookie header.
setSecure(boolean flag) Indicates whether the cookie should only be sent using a secure protocols, such as HTTPS or SSL or not.
setValue(String newValue) Assigns a new value to a cookie after the cookie creation.
setVersion(int v) Sets the version of the cookie protocol.
toString() Constructs a cookie header string representation for the given cookie which is the format defined by the corresponding cookie specification.

Example 1

Test it Now

Output:

Comment: This is for tutorial purpose.
The required domain is: javatpoint.com
The maximum age is given as: 2000
Name for the cookie is given as: Java
The hash code for the given cookie is given as: -357741581 

Example 2

Test it Now

Output:

The discard attribute is given as: true
The version is given as: 1
The value is given as: Hello
Check whether cookie has expired or not: false
Check whether the cookie contains the HttpOnly attribute or not: true
Next Topicclone() Method





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA