Avoiding Spring MVC Redirect URL Parameter Unwrap
I like Spring MVC. It is a great next step in the Spring history of Java/Web development.
I don’t like that Spring has decided that if you redirect from a POST then it unwraps all request parameters and throws them onto all subsequent URLs that are generated.
We have what I think is a fairly common search/results page. We POST the search criteria when the user changes some aspect and GET to perform manipulations within a search result (such as page, paging, or sorting).
I had been storing the criteria in the model passed to the POST request. This appears to be the culprit.
If I remove the model setting of the criteria and just store the criteria in the true HTTP session and redirect to my GET handler then everything works correctly. No ugly URLs with umpteen parameters off the side of the screen.
So, the order of steps is something like:
- User changes criteria and POSTS to handler
- POST handler stores criteria POJO in the HTTP request object and redirects to same page GET handler
- GET handler retrieves criteria from HTTP session and performs updated query
