3

I was wondering why Spring @PathVariable in the Controller is removing the spaces at the end of a word. for example my ajax is sending XYZ123. When this message is bind to a String with @PathVariable the ending space is removed by Spring. While it is send to the server as the correct String with the space.

The URL is send to the controller like

http://mydomain.com/user/XYZ123%20

and still spring is removing the space.

Is this just a bug, or is there a reason for it?

Khaled.K
  • 5,828
  • 1
  • 33
  • 51
Jimmy Geers
  • 670
  • 1
  • 13
  • 31
  • Can you please check [another post][1] talking this URL problems. [1]: http://stackoverflow.com/questions/3526523/spring-mvc-pathvariable-getting-truncated – Krishna Apr 28 '14 at 10:20

1 Answers1

0

That is probably due to the fact the additional trailing whitespace means nothing to a URL. In other word, both "http://mydomain.com/user/XYZ123" and "http://mydomain.com/user/XYZ123 " convey the same meaning.

If you want the space to persist, try URLEncoder-it, eg:

http://mydomain.com/user/XYZ123%20

gerrytan
  • 40,313
  • 9
  • 84
  • 99
  • Hello Gerrytan thanks for you answer, but that is just the thing the url is encoded like 'http://mydomain.com/user/XYZ123%20' and still spring is binding it without the trailing space. I have updated my question with your input. Thanks – Jimmy Geers Apr 28 '14 at 07:14