top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How does Cookies work in Servlets?

0 votes
422 views
How does Cookies work in Servlets?
posted Sep 15, 2017 by Pooja Singh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Cookies are used a lot in web client-server communication, it’s not something specific to java. Cookies are text data sent by server to the client and it gets saved at the client local machine.

Servlet API provides cookies support through javax.servlet.http.Cookie class that implements Serializable and Cloneable interfaces.

HttpServletRequest getCookies() method is provided to get the array of Cookies from request, since there is no point of adding Cookie to request, there are no methods to set or add cookie to request.

Similarly HttpServletResponse addCookie(Cookie c) method is provided to attach cookie in response header, there are no getter methods for cookie.

answer Sep 16, 2017 by Ayush Srivastav
Similar Questions
+2 votes

• Cookie 1 Name: IPAddress
• Cookie 1 Value: the client's IP address
• Cookie 2 Name: VisitTime
• Cookie 2 Value: the timestamp where the

...