1

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".

2
  • What about @PathVariable? you can use path="/signup-submit/{originURL}" and @PathVariable(value="originURL") String originURL Commented Apr 18, 2017 at 14:58
  • @StanislavL I think this only works for URL path parts, not query parameters. Moreover, how do I get something only if it's present as a POST body parameter only ? Commented Apr 18, 2017 at 15:05

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.