How to deal with browser button problem using spring?

How to deal with browser button problem using spring ?.

In my correct correct login to the system the application, and when the user clicks the back button, the page state is not supported. So I maintain the state of the page, even if the user clicks the back / forward button

thanks

+4
source share
3 answers

Pages are apparently being requested in the browser cache. You will need to disable client-side caching on the relevant pages. You can do this by creating a Filter that listens for the url-pattern pages you want to disable the cache on, for example *.jsp . Complete the following steps 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); 

Thus, the client application will be instructed not to cache requests matching the url-pattern this filter. When you click on the "Back" button, a real request from the server with the proposed new data will be forcibly submitted. To save specific server data between requests, you need to capture the session area or use only GET requests.

Oh, do not forget to clear the browser cache first after implementation and before testing;)

+5
source

Configure the interceptor inside the servlet context as follows:

 <mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/**/*"/> <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> </mvc:interceptor> </mvc:interceptors> 

Note. Remember to remove the browser cache while testing your application.

0
source

Source: https://habr.com/ru/post/1301080/


All Articles