The Hypertext Transfer Protocol (HTTP) is the network protocol that the web servers and the client browsers use to communicate with each other. The HTTP is a stateless protocol. A client browser opens a connection and requests for a resource from the web server. The web server then responds with a requested resource and closes the connection.
Cookies are small textual files that a web server may send to the user’s web browser which in turn saves it to the hard disk (or if they are temporary in the web browser’s memory). The server sends the cookie to the browser in response to an initial request. Subsequent request sends the same cookie back to the server, which enables the server to identify these requests as being from the same client. By letting the server read information it send to the client previously, the site can provide visitors with a numbers of benefits such as,
• Saving login identity i.e. user names.
• Identifying a user during e-commerce session.
• It let sites remember which topics interest certain users and show advertisements relevant to those interests.
• Frequent visitor bonuses.
• Bookmarks : Cookie let the use remember where he was when he last visited the site.
• Games : Cookie let remember the current or highest scores and present new
challenges based on past answers and performance.
In the simplest form, cookies store data in the form of name-value pairs with certain additional attributes which are exchanged in the response and request headers. Each attribute/value pair is separated by a semicolon. The web servers send a cookie by sending the user-cookie response header in the following format
set-cookie: Name= Value; Comment= COMMENT; Domain= DOMAINNAME;
Max-age= SECONDS ; Path= PATH; Secure; Version = 1*DIGIT
• Name is the name of the cookie.
• Value is the value this name can hold.
• Comment is an optional parameter that specifies the purpose associated with the cookie.
• Domain is an optional parameter that is used to specify the domain to which the cookie will be sent in future requests. By default, it is the host name of the domain that has sent the set-cookie header.
• Max-age is an optional parameter that specify how long (in seconds) the browser should keep the cookie before it expires.
• Path is an optional parameter that specifies the URL path for which the cookie
• The Secure parameter specifies whether the cookie should be sent only over a
secure connection (HTTPS). By default its value is false.
String getComment ()
Returns the comment associated with the cookie.
String getDomain ()
Returns the domain limitation associated with the Cookie.
int getMaxAge ()
Returns the maximum age allowed for this cookie.
String getPath ()
Returns the path limitation fort this servlet.
boolean getSecure ()
Returns true if this cookie requires a secure connection.
String getName ()
Returns the name of the cookie.
String getValue ()
Returns the value of the cookie in string format.
Sets the comment that describe the cookie’s purpose.
Specifies the domain within which the cookie should be presented.
Sets the maximum age of cookie in seconds.
Specifies the path for the cookie to which the client should return the cookie.
Assigns a new value to a cookie after the cookie is created.
Some methods of Cookie class