How to perform Logout Servlet?

How to perform logout in the servlet, so that after logout it was impossible to return "Back" button of browser? At the moment the servlet for logout 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");
}
 }
April 7th 20 at 15:42
0 answer

Find more questions by tags Java servletsUser identification