开发者

Disabling session when clicking Log out button and redirecting to Login page with message

开发者 https://www.devze.com 2023-03-07 08:17 出处:网络
i want to disable sesssion on button click in an jsp page i know: <button type=\"button\">Log out!</button>

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();
0

精彩评论

暂无评论...
验证码 换一张
取 消