1 of 6

Advanced java programming

Cookies

Smt.M.Jeevana Sujitha

Assistant Professor

Department of Computer Science and Engineering

SRKR Engineering College, Bhimavaram, A.P. - 534204

2 of 6

OBJECTIVES

The Objective of this lecture is

  • To learn about cookies in servlets.

3 of 6

Cookies

  • Cookies are small programs which can make use of information submitted on currently accessed web pages.
  • Cookies are one of the solutions to session tracking.
  • A cookie is a key-value pair created by the server and is installed on the client’s browser when the client makes a request for the first time.

4 of 6

Cookies

  • Browsers also maintained a list of cookies installed in them and send them to the server as a part of sub sequent HTTP Requests.
  • The server can then easily identify that this request is a part of a sequence of related requests.
  • That is why cookies provide an elegant solution to session tracking.
  • Cookie is represented using the class Cookie. Syntax:

Cookie(String key, String value);

5 of 6

Cookies

  • The cookie is added by the addCookie() method of the HttpServletResponse interface.
  • The server can get all cookies sent by

the web browser method of the

using getCookie() HttpServletRequest

interface.

6 of 6

THANK YOU