0

I have read that there is the method logout() that we can use in servlets. So,I am doing something like this

HttpSession sr=request.getSession();
sr.logout();

But this gives me an error that it cannot find the symbol logout(); Plz help.I want the user to logout and go to home page(home.jsp).

2 Answers 2

1

HttpServletRequest has a logout method, but it assumes you are using the servlet way of doing security. It clears the security context, but won't clear your session.

If you just want to clear the session, do

HttpSession sr = request.getSession();
sr.invalidate();
0
0

There is no logout method exist in HttpSession

//This code will redirect to  homepage.jsp
 RequestDispatcher rd = request.getRequestDispatcher("homepage.jsp");
  rd.forward(request, response);

You can use session.invalidate(); to invalidate the session

1
  • @saumyaraj Yes it will delete everything in the session (attribute..etc). Apr 19, 2013 at 13:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.