[英]Disable browser back button in spring mvc application after logout
I am doing spring mvc application in this when i logout from the application if i click browser back button its getting to the previous page of the application I have to restrict this and I tried this in my *.xml file当我从应用程序注销时,我正在做 spring mvc 应用程序,如果我单击浏览器后退按钮,它会进入应用程序的上一页我必须限制这个,我在我的 *.xml 文件中尝试了这个
<interceptors>
<beans:bean id="webContentInterceptor"
class="org.springframework.web.servlet.mvc.WebContentInterceptor">
<beans:property name="cacheSeconds" value="0" />
<beans:property name="useExpiresHeader" value="true" />
<beans:property name="useCacheControlHeader" value="true" />
<beans:property name="useCacheControlNoStore" value="true" />
</beans:bean>
</interceptors>
this is working only with in the application if I logout again if I click browser back button going to the previous page.如果单击浏览器后退按钮转到上一页,则仅在我再次注销时才可在应用程序中使用。
I tried with Javascript and Jquery examples but not working in my spring mvc application.我尝试了 Javascript 和 Jquery 示例,但在我的 spring mvc 应用程序中不起作用。 can any one please suggest me in this regard and approach to follow.
任何人都可以在这方面给我建议和遵循的方法。
Ok, Here I give you an idea with how you can do that.好的,我在这里给你一个关于如何做到这一点的想法。 Suppose you have a
SessionFilter
Class in package com.test.filter
that implement Filter
.假设您在
com.test.filter
包中有一个SessionFilter
类,它实现了Filter
。 Here you override the doFilter()
method and checked that if session exist or not such like that:在这里,您覆盖
doFilter()
方法并检查会话是否存在,例如:
public class SessionFilter implements Filter {
@Override
public void doFilter(ServletRequest req, ServletResponse res,
FilterChain chain) throws IOException,
ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
String url = request.getRequestURI();
response.setHeader("pragma", "no-cache");
response.setHeader("Cache-control", "no-cache, no-store, must-revalidate");
response.setHeader("Expires", "0");
HttpSession session = request.getSession(false);
//!url.contains("login.html") check if the requested page is login page or not. you can do it a numerous way.
// but for simpplicity here i do that
if(session==null && !url.contains("login.html")) {
response.sendRedirect(request.getContextPath() + "/login.html"); // here goto http://yourdoamin/login.html
response.setHeader("message", "Session Timeout."); // you can set your preffered message.
return; //break filter chain, requested JSP/servlet will not be executed
}
chain.doFilter(req, res);
}
}
Now add the class reference in to web.xml
现在将类引用添加到
web.xml
<filter>
<description>session filter</description>
<filter-name>SessionFilter</filter-name>
<filter-class>com.test.filter.SessionFilter</filter-class>
</filter>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.