I have a Spring 3.2 Controller with basic request mappings like
@RequestMapping("/action")
public String action(@RequestParam("param") String param) {
//do stuff...
return "view";
}
This controller handles links created by non-technical business users. Sometimes the users mess it up and create links with duplicate parameters, e.g.,
www.example.com/action?param=value¶m=value
The parameter is an exact duplicate and probably a copy/paste error.
My problem is that Spring is concatenating these dupes together, so that the url above will give "value,value"
for param
, when I want only "value"
.
What is a good way to detect and handle these duplicates? I know I could change all my @RequestParam
s to List<String>
s and go from there, but that's a whole lot of boilerplate over dozens of request mappings.
Ideally there would be a way to intercept and modify the url parameters before Spring attempts to bind them -- but only for this controller.
?param=value¶m=value
is not the same as?param=value
only. So if Spring did that "merging" in any way, it would be an invalid behavior. So, yeah, you have to implement it yourself. Be it through a new...ArgumentResolver
or...Interceptor
.HandlerInterceptor
was my first thought too, but you can't modify parameters from there.HttpServletRequest
in aHttpServletRequestWrapper
(see: stackoverflow.com/questions/1413129/… ).Filter
rather than a SpringHandlerInterceptor
then yes. I feel like a solution should exist higher than the servlet level though.