0

I am using Spring MVC.

I am sending a POST request from an Ajax context and I sent one parameter. The Content-Type of the request is {'Content-Type':'application/json;'} and in Firefox's Firebug I see the post request is sent with one parameter:

JSON
orderId "1"

Source
{"orderId":"1"}

How can I get it in my controller in the server? The signature of my method is:

@ResponseBody
@RequestMapping(value = "/blahblah", method = RequestMethod.POST)
public void blahblah(@RequestBody(required=false) String orderId ){...

The incoming orderId is always null. Any ideas?

Thanks..

UPDATED: I used {'Content-Type':'application/x-www-form-urlencoded;'} and send my parameters in the following format "orderId=" + id . Also, I changed the server method using @RequestParam String orderId and the value is passed.

2
  • what does your web server log say ? Are you sure the requestmapping is correct May 14, 2014 at 12:32
  • Yes, the requestmapping is not the problem.
    – pappus
    Jun 12, 2014 at 10:06

1 Answer 1

1

I used {'Content-Type':'application/x-www-form-urlencoded;'} and send my parameters in the following format "orderId=" + id .

I changed also the server method using @RequestParam String orderId and the value is passed.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.