Skip to main content
added 28 characters in body
Source Link
Alex Wittig
  • 2.9k
  • 3
  • 34
  • 43

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&param=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 @RequestParams 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.

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&param=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.

What is a good way to detect and handle these duplicates? I know I could change all my @RequestParams 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.

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&param=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 @RequestParams 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.

Source Link
Alex Wittig
  • 2.9k
  • 3
  • 34
  • 43

handle duplicate values for Spring @RequestParam

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&param=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.

What is a good way to detect and handle these duplicates? I know I could change all my @RequestParams 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.