Get cookies / web browser

1

I know that java gives us the ability to manipulate cookies, but there goes the question.

Is it possible to get cookies from the web browser? if yes, from which method?

    
asked by anonymous 24.11.2014 / 05:25

1 answer

4

See if the method below helps you:

Cookie[] cookies = request.getCookies();

if (cookies != null) {
    for (int i = 0; i < cookies.length; i++) {
        Cookie c = cookies[i];
        System.out.println("Nome: " + c.getName());
        System.out.println("Valor: " + c.getValue());
    }
}

Remembering that to get request through JSF, just do this:

FacesContext facesContext = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest) facesContext.getExternalContext().getRequest();
    
24.11.2014 / 11:23