如何使用Spring处理后退浏览器按钮问题? [英] How to handle back browser button problem using spring?

查看:106
本文介绍了如何使用Spring处理后退浏览器按钮问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用spring处理后退浏览器按钮问题?.

How to handle back browser button problem using spring?.

在我的应用程序中,用户正确登录并且当用户单击后退"按钮时,页面状态无法保持.那么即使用户单击后退按钮/前进按钮

In my application user login properly and when user click on back button page state is not maintained. So do i maintain the page state even the user click on back button / forward button

谢谢

推荐答案

显然,页面是从浏览器缓存中请求的.您需要禁用相关页面的客户端缓存.为此,您可以创建一个Filter,该Filter侦听您要为其禁用缓存的页面的url-pattern,例如*.jsp.在doFilter()方法中执行以下操作:

Apparently the pages are been requested from the browser cache. You'll need to disable the client-side caching of the pages in question. You can do this by creating a Filter which listens on an url-pattern of the pages you'd like to disable the cache for, such as *.jsp. Do the following in the doFilter() method:

HttpServletResponse httpres = (HttpServletResponse) response;
httpres.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
httpres.setHeader("Pragma", "no-cache"); // HTTP 1.0.
httpres.setDateHeader("Expires", 0); // Proxies.
chain.doFilter(request, response);

这样,将指示客户端应用程序缓存与该过滤器的url-pattern相匹配的请求.然后,按下后退"按钮将强制服务器发出带有新提议数据的 real 请求.要在请求之间保留某些服务器端数据,您需要获取会话范围或仅使用GET请求.

This way, the client side application will be instructed to not cache the requests matching the url-pattern of this filter. Pressing the back button would then force a real request from the server, with the proposed fresh data. To retain certain server-side data between the requests, you'll need to grab the session scope or use GET requests only.

哦,别忘了在实施之后和测试之前先清除浏览器缓存;)

Oh, don't forget to clear the browser cache first after implementing and before testing ;)

这篇关于如何使用Spring处理后退浏览器按钮问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆