Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 333
Vicky Avatar asked Feb 12 '10 05:02

Vicky


People also ask

What happens when browser Back button is pressed?

For pages that are set as non-cached, the browser reloads the page from the server when you press Back, as though it was the first time you are visiting it. For cached pages, the browser displays it out of the cache, which is much faster.

Can we use spring boot as backend?

Spring Boot and Angular form a powerful tandem that works great for developing web applications with a minimal footprint. In this tutorial, we'll use Spring Boot for implementing a RESTful backend, and Angular for creating a JavaScript-based frontend.


2 Answers

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

like image 141
BalusC Avatar answered Nov 15 '22 08:11

BalusC


you can use Spring Web Flow

I recommend this link to check about Spring web flow

like image 34
Priyan at Dialog Avatar answered Nov 15 '22 07:11

Priyan at Dialog