jeudi 9 avril 2015

Why the client cookie is still there and can not be removed?

I use below servlet code try to remove client cookie for log out:


LogoutServlet.java



Cookie cookies[]=request.getCookies();

if(cookies!=null){
for(int i=0;i<cookies.length;i++){
if(cookies[i].getName().equals("userName")){
cookies[i].setMaxAge(0);
cookies[i].setPath("/");
response.addCookie(cookies[i]);
break;
}
}
}

request.getRequestDispatcher("/login.jsp").forward(request, response);


The page jump to login.jsp I can see set-cookie in firebug(Expires is 1970 to remove cookie)



Set-Cookie userName=abc; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/


But when I enter xxx/login.jsp the client cookie is still there,I can still see the cookie in the request header by firebug



Cookie userName=abc; JSESSIONID=049034043CC3DD1231A52A534F60483B4;




Aucun commentaire:

Enregistrer un commentaire