也有類似的鏈接,但我還沒有找到任何解決方案爲我工作,所以我想知道如果有人可以給我一個工作示例我的方案。我正在做一個Ajax來從服務器端檢索數據,所以我可以在客戶端動態地創建圖表。我是否需要包含MappingJacksonHttpMessageConverter?如果這是答案,有人可以提供一個例子,我可以按照這個?Spring MVC發送responsebody對象到ajax後給出了406錯誤
的Java:
@RequestMapping(value="/getReportData.html", method=RequestMethod.GET, produces="application/json")
public @ResponseBody Reports getReport1Data(HttpServletRequest request)
{
System.out.println("Report 1 Page GET Method");
ModelAndView mv = new ModelAndView("report1");
if((Reports)request.getSession().getAttribute(USER_SESSION_REPORTS) != null){
reports = (Reports)request.getSession().getAttribute(USER_SESSION_REPORTS);
System.out.println("--------> Report 1 Page with session data");
return reports;
}
else{
System.out.println("--------> Report 1 Page with NO session data");
}
mv.addObject("report1", reports.getReport1());
return null;
}
的Javascript:
function getData(){
$.ajax({
url: "getReportData.html",
type: "GET",
contentType: "application/json",
dataType: JSON,
success: function(report1){
console.log("success: " + report1.utilRatio.decRatio);
},
error: function(report1){
console.log("error: " + report1.utilRatio.decRatio);
}
});
}
響應頭: 內容語言: 「恩」, 內容長度:「1110 「 內容類型: 「text/html的;字符集= UTF-8」 服務器: 「Apache的狼/ 1.1」
請求報頭: 接受: 「/」 接受 - 語言: 「EN-US,連接; q = 0.5」 接受編碼: 「gzip的,放氣」 內容類型: 「應用/ JSON」 X-請求-隨着:「XMLHttpRequ est「
可惜我還在做後得到一個406錯誤以上: 1)僅保留dataType,並將其設爲「json」 2)始終在每個場景中返回Reports對象 3)刪除所有modelAndView對象 ....仍然得到406這是令人沮喪的,這是我需要了解/得到,我會做的唯一部分:( – Glen
這些是我通過maven包括的圖書館,也許我失去了一個傑克遜我需要的圖書館? <! - JSON處理 - > \t \t \t com.fasterxml.jackson.core \t \t 傑克遜核 \t \t 2.5.1 \t \t \t \t 融爲一體。 fasterxml.jackson.core \t \t 傑克遜 - 數據綁定 \t \t 2.5.1 \t \t \t com.fasterxml.jackson.core \t \t 傑克遜 - 註解 \t \t 2.5.1 \t –
Glen