Destroy session in JSP

Abrah picture Abrah · Apr 3, 2013 · Viewed 44.2k times · Source

I am new to JSP. I have created set of pages in web application using login system.

I want to do log out option, and it should be appeared on every page.

Please I need the full source code.

Answer

Ajay S picture Ajay S · Apr 3, 2013

Use the session object in JSP to expire the session.

session.invalidate(); 

UPDATE

Make a separate header page and show sign out option when the user has signed on. After clicking on the sign out then do as I told you.

After destroying the session then redirect the user to home page.

response.sendRedirect("home.jsp");