Get cookies/browser

Asked

Viewed 243 times

1

i know java provides us the possibility to manipulate cookies, but there goes the question.

is it possible to obtain cookies from the web browser ? if yes, from which method ?

1 answer

3

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 the request through JSF, just do so:

FacesContext facesContext = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest) facesContext.getExternalContext().getRequest();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.