There's a web programming technique called Post+Redirect+Get that tries to avoid duplicate form submissions when hitting the refresh button.
This pattern is also discussed in the following thread:
How to avoid resubmit in jsp when refresh?
The problem is, this technique does not work in scenarios where after the redirection I need to render the result view using the submitted parameters. Since the second request (the one that requests for the result page) has no parameters submitted with.
In my specific scenario, I have a search form, that returns a list of books according to the filled in criteria. In the result page, the original search form is shown in the header, re-filled with the parameters that were submitted (as is done in Google search). Suppose each book on the received list is presented in such a way that you can edit its details. So the user edits one of the books on the list, and submits the edited list (i.e. by this he submits both the edited book and the original search criteria). The application should now both update the database and search the database again according to the submitted criteria. So I can do the database updating before the redirection. But I cannot do the new search after the redirection since by this time I do not have the criteria parameters.
I have seen two solutions:
Before the redirection, save the submitted parameters on the session, then read them from the session after the redirection when you render the result view (and maybe remove them from the session after you are done). ---> I prefer not to use this method since I do not want to use the session for that aspect of my application.
When you redirect to the result URL, concatenate the submitted parameters to the URL (as done in GET requests) (or anyway only those parameters that you will need for rendering the result view), this way you can have the parameters after the redirection when you render the result view ---> An OK solution, not too happy with it since the user will get the result view with a very long URL.
My question is, have you come across any other method - preferably elegant - to solve this problem?
Thanks!!
P.S. I am using Java and the Spring Framework but I think my question is applicable to any reasonable web framework.