spring後臺返回json數據 頁面406錯誤 Not Acceptable解決

使用SpsringMVC,controller請求設置如下: 
Java代碼  收藏代碼
  1. @RequestMapping(value="/list",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)  
  2. @ResponseBody  
  3. public List<EditTimeout> list(){  
  4.      List<EditTimeout> list = editImpl.selectAll();  
  5.     return list;  
  6. }  


ontroller執行正常,jquery.ajax始終無法執行回調函數

加入錯誤查看代碼:

[javascript] view plain copy
  1. error: function(XMLHttpRequest, error, errorThrown){  
  2.       alert(error);  
  3.       alert(errorThrown);  
  4.       },  

提示: Not Acceptable

The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers ().


Response RAW返回值如下,(前半部分) 
Xml代碼  收藏代碼
  1. HTTP GET http://127.0.0.1:8080/onlineLibrary/rest/system/editTimeout/list  
  2. Host: 127.0.0.1:8080  
  3.   
  4.   
  5. 406 Not Acceptable  
  6. Date: Sat, 17 Aug 2013 11:01:07 GMT  
  7. Server: Apache-Coyote/1.1  
  8. Content-Length: 1067  
  9. Content-Type: text/html;charset=utf-8  
  10. <html><head><title>Apache Tomcat/7.0.34 - Error report</title><style>  


引起的原因: 
   由於設置了@ResponseBody,要把對象轉換成json格式,缺少轉換依賴的jar包,故此錯。 
解決辦法: 

   加入依賴的jar,jackson-core-asl-1.9.12.jar,jackson-mapper-asl-1.9.12.jar問題解決。

啓動註解掃描要寫成 : <mvc:annocation-driven/>

發佈了25 篇原創文章 · 獲贊 46 · 訪問量 18萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章