What are cookies and how will you use them?

Answer Posted / janet

Cookies are a mechanism that a servlet uses to have a
client hold a small amount of state-information associated
with the user.
a) create a cookie with the cookie constructor:
public Cookie(String name,String value)
b) A Servlet can send a cookie to the client by passing a
Cookie object to the addCookie() method of
HttpServletResponse:
public void HttpServletResponse.addCookie(Cookie
cookie)

c) A servlet retrieves cookie by calling the getCookies()
method of HttpServletRequest:
public Cookie[]HttpServletRequest.getCookie().

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is servlet and its types?

553


Can we use the constructor, instead of init(), to initialize servlet?

580


How servlet is created?

540


Explain the servlet context.

596


explain the advantages of servlet life cycle?

553






What are Servlets?

596


What are the drawbacks of cgi?

566


Explain load on start-up and its importance?

594


What if we pass negative value in load-on-startup?

798


What are the advantages of Servlet over CGI?

662


Can filter be used as request or response?

540


What is called servlet container?

658


Which application server is best for java?

556


What is setattribute in servlet?

550


Can you explain in detail 'javax.servlet' package?

544