我查看了这个问题的所有其他答案并尝试了大部分解决方案,但似乎没有任何效果。我正在使用 Dojo.xhrPOST(xhrArgs),它显然位于 xhrArgs 定义之后。
我的 xhrArgs:
xhrArgs =
{
headers:
{
'Accept': 'application/json',
'Content-Type': 'application/json'
},
'url': thisUrl,
'postData':requestString,
'dataType' : 'json',
'userId': userId,
'measurementSystem': measurementSystem,
'systemId': openedSystemId,
'handleAs': 'text',
'load': function(data)
{
// Replace newlines with nice HTML tags.
data = data.replace(/\n/g, "<br/>");
dojo.byId(target).innerHTML = data;
},
'error': function(error)
{
dojo.byId(target).innerHTML = error;
}
};
和我的 Controller 方法签名和注解如下
@RequestMapping(value="/saveSystemConditions", method= RequestMethod.POST, headers = {"content-type=application/json"})
public String saveSystemConditions(HttpServletRequest request, HttpServletResponse response, @Valid @RequestBody Load load, BindingResult result)
我在 xhrArgs 中显示的 requestString 是
"{'systemID':'76', 'system.systemType':'1', 'unitsOfMeasure':'english', 'loadID':'63', 'dispersionInstallationLocation':'Duct+or+AHU', 'humidificationSystemType':'1', 'totalAirVolume':'1200.0', 'desiredDryBulb':'70.0', 'desiredAirMoistureType':'2', 'desiredAirMoisture':'55.0', 'outsideAirConditionsType':'1', 'outsideAirIntakeRateMeasuredAs':'0', 'loadCountry':'United+States', 'outsideAirVolumeMeasuredIn':'0', 'loadState':'Minnesota', 'outsideAirIntakeRate':'25.0', 'loadCity':'Minneapolis', 'elevationFeet':'837.0', 'outsideDryBulb':'-6.8', 'outsideAirMoisture':'57.3', 'userEnteredLoad':'7.43'}"
我明白了 415(不支持的媒体类型)
如有任何建议,我们将不胜感激。 大卫
最佳答案
spring mvc 映射处理程序的显式声明以及 <mvc:annotation-conig />
是一个问题.
关于ajax - Spring MVC Controller 抛出 415 错误媒体不支持 JSON 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14432695/