Reputation: 27296
I am using the @RequestParam annotation to instruct Spring MVC to inject a "web request parameter" (as the Javadoc calls them) into a method call in my code:
@RequestMapping(path="/signup-submit", method=RequestMethod.POST)
public String signupSubmit(@RequestParam(value="originURL", required=true) String originURL ...) {
...
I am bothered by the fact that this annotation apparently works both for POST parameters and for URL query parameters. I.e. looking at the above code it is not possible to say whether the originURL
is a POST body parameter or is a URL query parameter. Is there an annotation I can use to explicitly get it from either one or the other?
This is why I also place "web request parameter" in quotation marks as I don't think this is a technical term and I guess it is used in the loose sense of "some parameter either passed in the POST method body or as a query parameter in the URL".
Upvotes: 1
Views: 1395
Reputation: 400
Contrary to what cularis said there can be both in the parameter map.
The best way I see is to proxy the parameterMap and for each parameter retrieval check if queryString contains "&?=".
Note that parameterName needs to be URL encoded before this check can be made, as Qerub pointed out.
That saves you the parsing and still gives you only URL parameters.
The way can be getting query string..
public List<Topic> getTopics(HttpServletRequest req) {
String queryString = req.getQueryString();
.....
About "Web-Request-Parameter" (@RequestHeader), you are right as it consists of both params i.e. either are part of query or a part of request body.
Upvotes: 2
Reputation: 407
Not the exact solution to your problem. But seems like there's an easy hack for it. You can use @RequestBody
. This only looks for request body. If param is not found in request body, you can be sure that it is from request param.
Upvotes: 0