Write a servlet mapped to /logout , which then does something like this in doGet :
HttpSession session = request.getSession(false); if(session != null) session.invalidate(); request.getRequestDispatcher("/index.jsp").forward(request,response);
It doesn't matter if the user has a session or not, they will eventually be redirected to index.jsp .
source share