Reputation: 817
Controllers extending from SimpleFormController Http Method - Post
After the form is submitted and I press on browser back button, the page expired appears and I have reload the page which resubmits the form.
However, I need that when user clicks on browser back button, he is not shown page expired page, but instead user is redirect to form page.
I currently thought of two approaches:
Change from POST to get & use below in controller:
@Override
protected boolean isFormSubmission(HttpServletRequest request) {
return true;
}
Second way is to define cache time in constructor of controller:
public VehicleDescController()
{
setCacheSeconds(1);
}
The application is really old and uses XML based spring configurations. I am also relatively new to Spring MVC.
Please help me figure out the correct approach. Thanks.
Upvotes: 0
Views: 1352
Reputation: 2629
I normally like to have the Post method redirect to a Get method after it is done. You keep the Post method in place, but you always redirect to a Get method to display a resulting page. This will seem like a normal get operation to the user and you won't have the back browser issue.
If the Get method needs some data (example: a record id), then the Post can store that data in the user session and the Get method can look for that value in the user session. This is an easy way to "pass" data from the Post method to the Get method and it keeps that data in the user session if they do hit the back button to return to the page again.
Upvotes: 1