You are on page 1of 1

HttpCookies:----

Cookie is a file which store data sent from webserver to the client
Cookie stores the data in the form of key and value pairs
The key must be of type of String and value must be of type String
Cookie are sent from webserver to client in the form of HttpResponse Headers
Cookies are used to track the users in a site...Session Tracking
Cookies are used because Http is a stateless protocol
Cookie flow diagram
When a client sends a request to server,the server reads the HttpRequest Headers
to get the info related to cookies.
If the client does not have a cookie then the server add the cookie in the
HttpResponse Headers
The client now stores the cookie and uses the cookie for further requests.
Cookie is a class present in javax.servlet.http package.
Cookie object represnts the data in the form of key and
value pairs.
Cookie Constructors
Cookie()
Cookie(String name,String value)
Cookie class methods
void setName(String name)
String getName()
void setValue(String value)
String getValue()
Setting cookie as the response
void addCookie(Cookie cookie)---->HttpServletResponse
Cookie[] getCookies()------>HttpServletRequest

You might also like