所有工作正常,但註銷和會話銷燬無效,我不知道爲什麼。Java Session無效並且超時不起作用
爲什麼我可以訪問受保護的區域,如果會話無效或達到會話超時。
'http://localhost:8080/psg/admin/'
<security-constraint>
<display-name>My First Sec Constraint</display-name>
<web-resource-collection>
<web-resource-name>Protected Area</web-resource-name>
<url-pattern>/admin/*</url-pattern>
..
登錄的Servlet映射到/管理/映射到/管理
HttpSession session = request.getSession();
if (session != null) {
session.setAttribute("ID", session.getId());
session.setAttribute("User", request.getRemoteUser());
session.setAttribute("isAuthenticated", true);
getServletContext().getRequestDispatcher("/index.jsp").forward(request, response);
}
退出的Servlet /註銷
HttpSession session = request.getSession(false);
if(session!=null){
session.invalidate();
response.sendRedirect(request.getContextPath());
}
如果session-timeout必須銷燬會話,則會出現同樣的問題。 我還可以在此時間後得到一個有效的會話,如果我進入保護區/ PSG /管理/
<session-timeout>1</session-timeout>
您使用基本身份驗證嗎?然後,您的註銷將不起作用,因爲瀏覽器將重新發送每個請求的用戶憑據。 – Gas
是的,我使用Digist身份驗證。我認爲類似於基本。謝謝你的幫助。 – user3623194