Sr.Java Web Developer Question:
Download Job Interview Questions and Answers PDF
Tell me how does cookies work in Servlets?
Answer:
☛ 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.
☛ 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.
Download Sr.Java Web Developer Interview Questions And Answers
PDF
Previous Question | Next Question |
Tell us what kind of HTTP request does the <a href="url">text</a> generate? | Tell me what are the reasons for a page not found error and how will you sort it out? |