spring后台返回json数据 页面406错误 Not Acceptable解决

来源:互联网 发布:数据归一化公式 编辑:程序博客网 时间:2024/05/22 18:22
使用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/>

0 0
原创粉丝点击