2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

How does Cookies work in Servlets?

I listen about cookies from my team members and they are going to use in our servlet application but as I am a new commerce on this no idea about this. Can some body help me to learn cookies?
userimage

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 is