This tip shows the way to access the cookie information stored at the client side. To access the cookies information at the client side javax.servlet.http.cookies class is used.

The following code demonstrates this technique. It checks the existence of cookie ‘MyCookie’.

boolean Democookiefound = false;

Cookie[] cookies = request.getCookies();

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

    if(cookies[nIndex].getName().equals(“MyCookie”)){
        Democookiefound = true;
        //desired cookie found, use it
    }
    
}

if(Democookiefound == false) {
    //cookies not found.
}