0

Не могу коректно реализовать завершение сессии пользователя. После нажатия кнопки бек меня возвращает на авторизированное окно. Как сбросить сессию? Пробовал через фильтры тоде не получается. В логауте уже наворотив всего что можно.

public class LogoutServlet extends HttpServlet {

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("text/html;charset=UTF-8");
    String message = "Вы успешно вышли.";

    HttpSession session = req.getSession(false);

    Cookie[] cookies = req.getCookies();
    if (cookies != null) {
        for (int i = 0; i < cookies.length; i++) {
            Cookie cookie = cookies[i];
            cookies[i].setValue(null);
            cookies[i].setMaxAge(0);
            resp.addCookie(cookie);
        }
    }

    resp.setHeader("Cache-Control","no-cache"); //Forces caches to obtain a new copy of the page from the origin server
    resp.setHeader("Cache-Control","no-store"); //Directs caches not to store the page under any circumstance
    resp.setDateHeader("Expires", 0); //Causes the proxy cache to see the page as "stale"
    resp.setHeader("Pragma","no-cache"); //HTTP 1.0 backward
    session.removeAttribute("name");
    session.invalidate();
    req.getSession(true);

    RequestDispatcher rs = req.getRequestDispatcher("WEB-INF/jsp/index.jsp");
    req.setAttribute("message", message);
    rs.forward(req, resp);
}

}

1

1 ответ 1

1

После нажатия кнопки "назад" браузер берет страницу из внутренного кэша. Иногда это даже отдельный особый кэш исключительно для кнопок "Назад" и "Вперед".

Попробуйте после нажатия кнопки "Назад" обновить страницу.

1
  • Тогда даже session.атрибут возвращается и можно ходить по разным вкладкам.
    – helloWorld
    1 сен 2016 в 10:50

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.