Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
490 views
in Technique[技术] by (71.8m points)

jsp - How to handle back browser button problem using 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

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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);

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 ;)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...