Benzer bağlantılar var ama benim için çalışmak için herhangi bir çözüm bulamadım, bu yüzden birisinin bana senaryo için bir örnek verebileceğini merak ediyordum. Sunucu tarafında veri almak için bir ajax alıyorum, böylece istemci tarafında dinamik olarak grafikler oluşturabilirim. MappingJacksonHttpMessageConverter'i eklemem gerekir mi? Eğer cevabınız varsa, birisi bunun için bir örnek verebilir mi?Bahar MVC ajax gönderiye yanıt vermek için 406 hatası veriyor
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);
}
});
}
Yanıt Başlıkları: Content-Language: "tr", içerik-uzunluk: "1110 " Content-Type: "text/html; charset = utf-8" Sunucu: "Apache-Coyote/1.1"
talep Başlıkları: "/" yazısı kabul: Kabul Dil: "tr-tR, tr, q = 0.5" Accept-Encoding: "gzip, deflate" Content-Type: "application/json" X-Talep-With: "XMLHttpRequ est "
maalesef hala yaptıktan sonra 406 hatası alıyorum yukarıdaki: 1) yalnızca veri tipini koru ve "json" yaptı 2) her senaryoda her zaman geri döndürülen Reports nesnesini 3) kaldırıldı tüm modelAndView nesneleri .... hala sinir bozucu olan 406 alıyorum, bu anlamaya/almam gereken tek parça budur: ( – Glen
bunlar maven'e dahil ettiğim kütüphaneler, belki bir jackson eksik kütüphaneye ihtiyacım var? \t \t \t com.fasterxml.jackson.core \t \t Jackson çekirdekli \t \t 2.5.1 \t \t \t \t com. fasterxml.jackson.core \t \t Jackson-databind \t \t 2.5.1 \t \t \t com.fasterxml.jackson.core \t \t Jackson-açıklamalar \t \t 2.5.1 \t –
Glen