Mor*_*lor 9 java security session jsp invalidation
所以这就是问题所在.当用户退出我的网站时,他们仍然可以点击后退按钮并继续使用该网站.为了跟踪用户是否登录,我创建了一个会话属性"isActive".用户登录时该属性设置为true,并且在注销时会话无效之前(冗余)删除该属性.同样在每个页面上,我都会检查属性是否存在.
我还指定不应在其head标签中缓存页面.
尽管如此,用户仍然能够回击浏览器,并继续使用该网站,就好像他们从未注销过一样.
有关如何解决此问题的任何想法?
这是代码:
登录Servlet:
...
session.setAttribute("isActive", true);
//Redirect to home page.
Run Code Online (Sandbox Code Playgroud)
检查登录的JSP:
<c:if test='${empty sessionScope.isActive || sessionScope.isActive != true}'>
<c:redirect url="/index.jsp?message=Session Timed Out."/>
</c:if>
Run Code Online (Sandbox Code Playgroud)
注销Servlet:
request.getSession().removeAttribute("isActive");
request.getSession().invalidate();
response.sendRedirect("index.jsp");
Run Code Online (Sandbox Code Playgroud)
内部标记:
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Expires" content="Sat, 01 Dec 2001 00:00:00 GMT">
Run Code Online (Sandbox Code Playgroud)
谢谢
Bal*_*usC 11
元标记是不够的.您需要将它们添加为完整的响应标头.webbrowser依赖于它们.A Filter
对此很有帮助.此外,Cache-Control
标头不完整(在Firefox等中无法正常工作).
在例如映射的doFilter()
方法中实现Filter
它(如果要覆盖所有JSP页面).url-pattern
*.jsp
HttpServletResponse res = (HttpServletResponse) response;
res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
res.setHeader("Pragma", "no-cache"); // HTTP 1.0.
res.setDateHeader("Expires", 0); // Proxies.
chain.doFilter(request, response);
Run Code Online (Sandbox Code Playgroud)
这样,webbrowser将被强制在服务器上发出实际请求,而不是从浏览器缓存中显示页面.此外,您应该使用a Filter
来检查登录用户的存在,而不是JSP/JSTL.