How to Read Client Side Cookies from a Servlet?

How to Read Client Side Cookies from a Servlet?

It is easy to read the cookies from a servlet.

Cookies[] getCookies() returns an array of Cookie objects.

// Check for cookies

Cookie[] cookies = request.getCookies();

// Check to see if any cookies exists

if (cookies != null)

{

for (int i =0; i< cookies.length; i++)

{

Cookie aCookie = cookies[i];

System.out.println (Name :  + aCookie.getName());

System.out.println (Value:  + aCookie.getValue());

}

}

If your site needs secure, high-performance hosting, visit our homepage to see our range of web hosting solutions.

Sharing

Pin It on Pinterest

Share This