Servlet Tutorials

Cookies in Servlet
Previous Home Next
adplus-dvertising

Cookies – it is a kind of text file, stored in the client machine inside cookies sub folder of user profile. Used to retrieving information for the clients. Every cookies has one expire date.


or

It is a kind of client side database, that stored on the client machine,used for retrieving information for the client.

How Cookie works

In Cookies is performed by default, for each request is considered as a new request and it is technique, we can add cookie with response from the servlet.

Then after cookie is stored in the cache of the browser.and now if request is sent by the user, cookie is added with request by default.So, we recognize the user as the old user.

There are 2 types of cookies in servlets.

  1. Non-persistent cookie
  2. Persistent cookie

Non-persistent cookie

Non-persistent cookie is valid for single session only and it is removed each time when user closes the browser.

Persistent cookie

Persistent cookie is valid for multiple session and it is not removed each time when user closes the browser. Persistent cookie is removed only if user logout or signout.

Advantage of Cookies

Maintaining the state.

Cookies are maintained at client side.

Disadvantage of Cookies

Cookies will be not work if cookie is disabled from the browser.

Only textual information can be set in Cookie object.

Note: Gmail uses cookie technique for login. If you disable the cookie, gmail won't work.
Previous Home Next