Servlet session invalidate

后端 未结 1 1367
误落风尘
误落风尘 2021-01-15 04:58

I have 2 apps in 2 different servers - Tomcat(basically a .WAR file) and a EAR in jBoss.

EAR is a reusable app where I will authenticate the user and send back the c

相关标签:
1条回答
  • 2021-01-15 05:10

    You don't need a Filter. A simple Servlet will do:

    public LogoutServlet extends HttpServlet {
        @Override
        public void doGet(...) {
           request.getSession().invalidate();
        }
    }
    

    Then map this servlet to /lougout in web.xml, and whenever the user wants to logout, he should be sent to http://youhost/yourapp/logout.

    If you want to log him out when he is already working with the tomcat server, you'd need to redirect back to the JBoss server to invalidate the session there.

    Note that request.getSession() gets the current session - i.e. the one that belongs to the user making the request. Your servlet container (server) handles this for you.

    0 讨论(0)
提交回复
热议问题