Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top