2

Using servlet 2.3 is there a way to log a user out when he has signed in using form authentication. I know servlet 3.0 has this feature of logging out. What should servlet 2.3 users do for logging out ?

Murphy316
  • 766
  • 3
  • 13
  • 29

2 Answers2

3

Just invalidate the session.

request.getSession().invalidate();

Don't forget to send a redirect afterwards.

response.sendRedirect(request.getContextPath() + "/login.jsp");
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks for clearing that up. I was actually forwarding it and getting funny behavior. Redirection did the trick. – Murphy316 Jun 28 '12 at 03:39
  • 2
    Yes, the session is still in the current request, but not anymore in the next request. – BalusC Jun 28 '12 at 03:41
1

Look here Regarding Logout. It also explains the difference between

Servlet 3.0 HttpServletRequest.logout()

and

session.invalidate() method.

Community
  • 1
  • 1
Ramesh PVK
  • 15,200
  • 2
  • 46
  • 50