Answer the question
In order to leave comments, you need to log in
How to correctly execute Servlet Logout?
How to correctly logout in a servlet so that after logout it is impossible to return "Back" using the browser button? At the moment, the logout servlet looks like this:
// Logout
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession();
String sessionId = session.getId();
UsersDataSet user = accountService.getUserBySessionId(sessionId);
if (user == null) {
response.setContentType("text/html;charset=utf-8");
response.getWriter().println("Unauthorized. (401)");
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
} else {
accountService.deleteSession(sessionId);
session.invalidate();
response.sendRedirect("/logout");
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question