Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring MVC @RequestParam values not being extracted from URI as expected

I am wondering how spring split each parameters of a http request. By example i have this method definition :

@RequestMapping(value = "/search.do", method = RequestMethod.GET)
public String searchGet(ModelMap model,
    @RequestParam(value = "memberId", required = false) Integer memberId,
    @RequestParam(value = "member", required = false) String member) {...}

and i use this url :

/search.do?member=T&O=

i get member = T and not member =T&O=

The request params are limited to only memberId and member. Can i configure spring for solving this problem ?

like image 519
revo Avatar asked Mar 15 '13 11:03

revo


2 Answers

Some characters in URLs have a special meaning. If they are supposed to be part of a value they need to be escaped.

If your value is T&O= then it needs to be changed to T%26O%3D

like image 197
a better oliver Avatar answered Sep 18 '22 22:09

a better oliver


Looking at your controller code, your URL should have been

/search.do?memberId=T&member=

Then request parameter names will get mapped correctly.

If you wish to use same URL as mentioned in your question, change controller code to :

public String searchGet(ModelMap model,
@RequestParam(value = "O", required = false) Integer memberId,
@RequestParam(value = "member", required = false) String member) {...}
like image 25
Jeevan Patil Avatar answered Sep 21 '22 22:09

Jeevan Patil