I have a Spring application that receives a request like http://localhost/foo?email=foo+bar@example.com
. This triggers a controller that roughly looks like this
SPR-6291 fixed this problem in v3.0.5
but this remains unresolved in some other cases like SPR-11047 is still unresolved. While SPR-6291's priority was Major, SPR-11047's priority is Minor.
I faced this problem when I was working on REST API in old Spring last year. There are multiple ways we can get data in Spring controller
. So two of them are via @RequestParam
or @PathVariable
annotation
As others mentioned I think its spring's internal issue and does not specifically belong to URL
encoding because I was sending data over POST
request but it is somewhat encoding problem. But I also agree with others as now it remains problematic only in URL
.
So there are two solutions I know:
You can use @PathVariable
instead of @RequestParam
because as of SPR-6291
this plus sign issue is fixed in @PathVariable
and still remains open for @RequestParam
as SPR-11047
My version of spring was not even accepting plus sign via @PathVariable
annotation, so this is how I overcome the problem (I don't remember it step by step but it will give you hint).
In your case you can get the fields via JS
and escape
the plus sign before sending a request. Something like this:
var email = document.getElementById("emailField").value;
email = email.replace('+', '%2B');