我正在尝试将jsonObject从jsp发布到控制器,我收到400 Bad Request Error。
我的jsp代码
$.ajax({
url : 'save.web',
type: "post",
dataType: 'json',
contentType:'application/json',
data: "data="+JSON.stringify(jsonArray),
success:function(data){
}
});
});
My json Object
var jsonArray="{"+'"'+"cds"+'"'+":"+"[";
for(i=0;i<newRow.length;i++)
{
jsonArray=jsonArray+"{"+'"'+"dno" +'":'+newRow[0]+","+'"'+"CampaignCode"
+'":'+newRow[1]+"," +'"'+"CampaignName"+'":'+newRow[2]+","
+'"'+"ServiceNo" +'":'+newRow[3]+"}";
}
jsonArray=jsonArray+"]}";
我的控制器代码
@RequestMapping(value = "/save.web", method = RequestMethod.POST)
@ResponseBody
public String save(WebRequest webRequest,Model model,HttpServletRequest
request, HttpServletResponse response,@RequestParam CampaignDisplay[] cds)
{
for(CampaignDisplay inputs : cds){
System.out.println(inputs.getId());
}
return "menu";
}
输入我传递的Json对象
{ “CDS”:[{ “DNO”:8中, “CampaignCode”:d “CAMPAIGNNAME”:E, “服务无”:F},
{“dno”:7,“CampaignCode”:a,“CampaignName”:b,“ServiceNo”:c}]}
我不知道为什么我会得到400个错误?我也设置了标题
答案 0 :(得分:0)
似乎控制器无法理解请求。原因是“您正在发布JSON,而不是表单数据,但您尝试将其作为表单参数读取”。 将您的方法更改为
**public String save(WebRequest webRequest,Model model,HttpServletRequest
request, HttpServletResponse response,@RequestBody Map<String, Object> inputParameter)
{**