Cookie Class in Servlet

A cookie is stored on a client and contains the state information. The Cookie class encapsulates a cookie. Cookies are valuable for tracking user activities. A cookie can save the user’s name, address, and other information. The user does not need to enter this data each time he or she visits the store. Some of the information that is saved for each cookie is given below:

    1. Name of the cookie
    2. Value of the cookie
    3. Expiration date of the cookie
    4. Domain and path of the cookie

Name and Values of the cookies are stored on the user’s machine.

Expiration date determines when this cookie is deleted from the user’s machine. If an expiration date is not explicitly assigned to a cookie, it is deleted when the current browser
session ends. Otherwise, the cookie is saved in a file on the user’s machine.

Domain and path of the cookie determine when it is included in the header of an HTTP request. If the user enters a URL whose domain and path match these values, the cookie
is then supplied to the Web server. Otherwise, it is not.

MethodDescription
Object clone( )It returns a copy of this object.
String getComment( )It returns the comment.
String getDomain( )It returns the domain.
int getMaxAge( )It returns the maximum age (in sec).
String getName( )It returns the name.
String getPath( )It returns the path.
boolean getSecure( )It returns true if the cookie is secure. Otherwise, returns false.
String getValue( )It returns the value.
int getVersion( ) It returns the version
void setComment(String c)It sets the comment to c.
void setDomain(String d)It sets the domain to d.
void setMaxAge(int secs)It sets the maximum age of the cookie to secs. This is the number of seconds after which the cookie is deleted.
void setPath(String p)It sets the path to p.
void setSecure(boolean secure)It sets the security flag to secure.
void setValue(String v)It sets the value to v.
void setVersion(int v)It sets the version to v.