如何使用spring mvc处理浏览器后退按钮

时间:2016-07-25 11:15:51

标签: java spring google-chrome spring-mvc servlets

我正在使用spring mvc,我正面临浏览器后退按钮的问题

当用户点击后退按钮时它没有击中服务器。 我已经返回了GET和POST方法来处理这个问题,但它并没有触及服务器本身。 通过使用过滤器从客户端删除缓存后。它无法正常工作

任何人都可以建议解决问题需要做些什么吗? 在此先感谢

*************过滤以删除缓存****************

@Override
public void doFilter(ServletRequest req, ServletResponse res,
        FilterChain chain) throws IOException, ServletException {
    System.out.println("Removing the cache from Request");
    HttpServletResponse response=(HttpServletResponse)res;
    response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
    response.setDateHeader("max-age", 0);
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", 0);
    chain.doFilter(req, res);
}

**********用于处理GET和POST请求的控制器********

@RequestMapping(value = "/myPage", method = RequestMethod.GET)
public String method()
{
    LOG.info("### Handling Get Request Started ###");

    return "/myPage";
}

@RequestMapping(value = "/myPage", method = RequestMethod.POST)
public String handlePostMethod(MyForm form,
        final BindingResult bindingResult)
{
    LOG.info("### Handling Post Request Started ###");
    return "/myPage"
}

回复标题:

POST /shop/login/cstbasereginputagree HTTP/1.1 
Host: localhost:9002 Connection: keep-alive Content-Length: 119
Cache-Control: max-age=0 Origin: localhost:9002
Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8 Accept-Encoding: gzip, deflate, br Accept-Language: ja,en-US;q=0.8,en;q=0.6

************* Web.xml ****************

<filter>
    <filter-name>NoBrowserCacheFilter</filter-name>
    <filter-class>com.web.filters.NoBrowserCacheFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>NoBrowserCacheFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

0 个答案:

没有答案