views:

380

answers:

1

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

+1  A: 

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 either copypasting the following into the HTML <head> element of each JSP page you'd like to have to be requested from the server side instead of from the browser cache:

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">

..or by creating a Filter which listens on an url-pattern of the pages you'd like to disable the cache for, such as *.jsp, and contains basically the following lines 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);

Either way, the client side application will be instructed not to cache the requests in question. 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 ;)

BalusC