i want to disable sesssion on button click in an jsp page
i know:<button type="button">Log out!</button>
<%session.invalidate();%>
开发者_如何学JAVA
how should i implement this ?
On click of button make a GET to a servlet, and in servlet invalidate the session and redirect it to login page
<a href="/app/logOutServlet">Log Out</a>
in servlet
doGet(....){
request.getSession().invalidate();
response.sendRedirect("URL_TO_LOGIN_PAGE");
}
Here is how I would do it:
- The button redirects to a Servlet, using either a form or JavaScript code (I would go for the form, I'm not such a big fan of JavaScript everywhere)
- The Servlet invalidates the session, using
request.getSession().invalidate();
精彩评论