Servlet Cookies ( Servlets session tracking with cookie )

Cookie is a file that contains textual information. It allocates memory at client side to store small amount of data that sends by a Web/Application server to a client in servlets.

cookies comes along with the server response and saved at the client side for the given domain name and path.
Whenever a client requests to the server, the cookie matching the domain name , path of the request URL. If it matches, the cookies goes to the server as a request headers.


Servlet Cookies The main advantage is , it reduces network traffic.

Servlet Cookies Security wise cookies are not good to use.Because they can be possible to view and modify.

Servlet Cookies Cookies are suitable and specific to the HTTP requests only.

Servlet Cookies Maximum size of a cookie is 4 KB. So it can store a small amount of data.

Servlet Cookies If the client machine disable cookies,they cannot be able to allocate memory in the client side.



Cookie cookie_object = new Cookie(name“,”value);


Servlet Cookies Example for a servlet cookies :

Servlet Cookie Directory structure in eclipse :
The sendRedirect



Servlet Cookie index.jsp

Servlet Cookie

Servlet Cookie

Servlet Cookie web.xml

Servlet Cookie Execution Result :

Enter the URL (http://localhost:8080/cookieExample/index.jsp) in the browser address bar.
The sendRedirect

Enter the details and click submit button. Based on selection, you will get the question like below.
The sendRedirect

Key in your answer and click submit button .Finally the server returns the result page.
The sendRedirect

Related Posts :
AES Password Encryption in javascript and decryption in java – servlet
Kill or invalidate session using session id ( concurrent login )
Servlet Filter ( Request and Response filters in servlets ) example
URL rewriting in servlets ( Servlet session tracking )
Hidden form field in servlets ( Servlet session tracking )
Request attributes in servlet with an example ( Attribute scope )
Session attributes in servlet with example (Attribute scope)
ServletConext Attributes in servlet ( Attribute scope )
   [will not be published]

^ <