In order to read cookies that come back from the client (browser) in request header, you need to call getCookies () method of the HttpServletRequest. If the request contains no cookies this method returns null.
The following statement retrieve the cookies sent in the request header.
Cookie  cookies = request.getCookies ();
Once you have an array of cookies, loop through the cookie array in order to retrieve information about each cookie.
The following code will retrieve the cookies sent by the client.
public class RetrieveCookie extends HttpServlet
Public void doGet (HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException
//set content type and other response header files first
//write the data of the response
out = response.getWriter ();
//get cookie from HTTP request header
Cookie  cookies = request.getcookies ();
out.println (“<HTML> <HEAD> <TITLE> Retrieving cookies </TITLE>
//check whether cookies exist
if (cookies != null)
for (int i=0; i<cookies.length; i++ )
//display these cookies
out.println (“Cookie Name:” + cookies [i].getName ());
out.println (“Value:” +cookies [i].getValue ());
out.println (“No cookies exist”);
out.println (“</BODY> </HTML>”);
Output: Cookie Name: name Value: daljeet
Cookie Name: email Value:
NOTE: When you loop through the cookie array. You might get irrelevant cookies in addition to the cookies send by you. If you want only to display the cookies send by you call getName () method on each cookie until you find one that matches with name of the cookie that you have set.