What is the best way to kill a session and remove a cookie?  I am developing a website where a user can login (it creates a session and then writes a cookie).  I also want to be able to log out so that the user can log in as someone else.  I need to kill the cookie, because I look for a cookie when a user visits the site, and I also need to kill the session.  This is what I currently do, and it seems to work most of the time, but sometimes it seems to think that the user is still logged in:
 
<%
 Cookie userCookie = new Cookie("DUH",null);
 // kill the cookie
 userCookie.setMaxAge(0);
 response.addCookie(userCookie);
 
 // kill the session
 if (session != null)
  session.invalidate();
 
 // now we go back to the login jsp
 response.sendRedirect (response.encodeRedirectUrl("login.jsp"));
 
%>
 
Does anyone see any problems with this code snippet?
 
Mike Begeman
Digital Prairie Systems, Inc.
 

Reply via email to