Olá, tudo bom?
Alguém poderia me ajudar, como recuperar o valor do cookie no jsp
//faço a chamada para gravar cookie
try {
/*inicio da gravação do cookie*/
Locale locale = request.getLocale();
String countryCodeAlpha2 = locale.getCountry();
Country country = countryDAO.searchByCountryCodeAlpha2(countryCodeAlpha2);
//System.out.println("country.getId(): "+country.getId());
Cookie cookie []=request.getCookies();
Boolean achou=false;
for(int i=0;i<cookie.length;i++){
if(cookie[i].getName().equals("countryId")){
achou=true;
}
}
System.out.println("achou: "+achou);
if(achou == false){
System.out.println("gravou......................... ");
String countryId = Long.toString(country.getId());
cookieController.saveCookie(countryId);
}
/*fim da gravação do cookie*/
} catch (Exception e) {
// TODO: handle exception
}
// grava cookie
public void saveCookie(String countryId) {
Cookie cookieCountryId = new Cookie("countryId", countryId);
cookieCountryId.setMaxAge(60*60*24*30);
cookieCountryId.setDomain(".xxx.com");
response.addCookie(cookieCountryId);
System.out.println("cookieCountryId.getValue(): "+ cookieCountryId.getValue());
}
até ai ok!
mas quando estou no jsp e tento exiber o valor do cookie não exibe nada, veja as formas:
||${cookie.countryId.value} ---------- ${cookie[“countryId”]} -------------- ${requestScope.countryId.value}||
aqui ${cookie} exibe o objeto, mas não consigo pegar o value
Desde já, obrigado.
At,