我试图将来自Ext JS的POST参数发送到Spring应用程序。这是我的控制器:
@RequestMapping(value = "/unloadCatalog", method = RequestMethod.POST)
public void unloadMappingCatalog(@RequestParam(required = true) String jsonString,
HttpServletRequest request, HttpServletResponse response)
{
这里是我用来发送这些参数的Ext JS片段:
var unloadData = Ext.encode(listObjects);
Ext.Ajax.request({
url:'content/unloadCatalog',
method: 'POST',
params:{
jsonString: unloadData
},
success: function(response, opts){
// do something
}
});
但是如果我发送json数据unloadData
作为正文数据
Ext.Ajax.request({
url:'content/unloadCatalog',
method: 'POST',
jsonData: unloadData,
success: function(response, opts){
// do something
}
});
并像这样更改我的控制器:
@RequestMapping(value = "/unloadCatalog", method = RequestMethod.POST)
public void unloadMappingCatalog(@RequestBody String jsonString,
HttpServletRequest request, HttpServletResponse response)
{
一切正常。为什么第一种情况不起作用?
答案 0 :(得分:3)
原因是默认情况下,如果您发布数据,数据将包含在请求正文中,并且您获得了内容类型:application/x-www-form-urlencoded