SpringMVC异常报406 (Not Acceptable)的解决办法
2017-02-02 16:47
423 查看
使用SpsringMVC,使用restEasy调试,controller请求设置如下:
Java代码
@RequestMapping(value="/list",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<EditTimeout> list(){
List<EditTimeout> list = editImpl.selectAll();
return list;
}
请求,debug跟踪list是返回值没有问题,但是前台页面报如下错误:
Java代码
Response Status: 406 (Not Acceptable)
Response RAW返回值如下,(前半部分)
Xml代码
HTTP GET http://127.0.0.1:8080/onlineLibrary/rest/system/editTimeout/list
Host: 127.0.0.1:8080
406 Not Acceptable
Date: Sat, 17 Aug 2013 11:01:07 GMT
Server: Apache-Coyote/1.1
Content-Length: 1067
Content-Type: text/html;charset=utf-8
<html><head><title>Apache Tomcat/7.0.34 - Error report</title><style>
后台提示错误:
Java代码
2013-08-17 19:01:03,116 DEBUG org.springframework.web.servlet.DispatcherServlet -Last-Modified value for [/onlineLibrary/rest/system/editTimeout/list] is: -1
2013-08-17 19:01:07,606 DEBUG org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver -Resolving exception from handler [public java.util.List<com.online.ol.filter.EditTimeout> com.online.ol.filter.EditTimeoutContoller.list()]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
2013-08-17 19:01:07,680 DEBUG org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver -Resolving exception from handler [public java.util.List<com.online.ol.filter.EditTimeout> com.online.ol.filter.EditTimeoutContoller.list()]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
2013-08-17 19:01:07,681 DEBUG org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver -Resolving exception from handler [public java.util.List<com.online.ol.filter.EditTimeout> com.online.ol.filter.EditTimeoutContoller.list()]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
自己在整合spingmvc的过程中,同样也是遇到了406的问题,前台ajax总是不能继续往下面执行,经过前台的检查元素,查看得知,状态码为406
如果当时没有在网上,查询结果,估计这个问题要困扰好久的。
在这里分享出来,虽然也是转载的,但是希望能够帮到更多的人解决这样的问题。
当时没有截图我自己的代码和错误提示,遇到这样问题的亲们,可以自行导包之后测试,我当时的错误就是没有导包造成的
如果亲们有其他的解决方法或者意见,请在下面留言,希望能帮到更多的人。
引起的原因:
由于设置了@ResponseBody,要把对象转换成json格式,缺少转换依赖的jar包,故此错。
解决办法:
加入依赖的jar,jackson-core-asl-1.9.12.jar,jackson-mapper-asl-1.9.12.jar问题解决。
jackson-mapper-asl-1.9.12.jar (762.1 KB)
jackson-core-asl-1.9.12.jar (226.8 KB)
Java代码
@RequestMapping(value="/list",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<EditTimeout> list(){
List<EditTimeout> list = editImpl.selectAll();
return list;
}
请求,debug跟踪list是返回值没有问题,但是前台页面报如下错误:
Java代码
Response Status: 406 (Not Acceptable)
Response RAW返回值如下,(前半部分)
Xml代码
HTTP GET http://127.0.0.1:8080/onlineLibrary/rest/system/editTimeout/list
Host: 127.0.0.1:8080
406 Not Acceptable
Date: Sat, 17 Aug 2013 11:01:07 GMT
Server: Apache-Coyote/1.1
Content-Length: 1067
Content-Type: text/html;charset=utf-8
<html><head><title>Apache Tomcat/7.0.34 - Error report</title><style>
后台提示错误:
Java代码
2013-08-17 19:01:03,116 DEBUG org.springframework.web.servlet.DispatcherServlet -Last-Modified value for [/onlineLibrary/rest/system/editTimeout/list] is: -1
2013-08-17 19:01:07,606 DEBUG org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver -Resolving exception from handler [public java.util.List<com.online.ol.filter.EditTimeout> com.online.ol.filter.EditTimeoutContoller.list()]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
2013-08-17 19:01:07,680 DEBUG org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver -Resolving exception from handler [public java.util.List<com.online.ol.filter.EditTimeout> com.online.ol.filter.EditTimeoutContoller.list()]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
2013-08-17 19:01:07,681 DEBUG org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver -Resolving exception from handler [public java.util.List<com.online.ol.filter.EditTimeout> com.online.ol.filter.EditTimeoutContoller.list()]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
自己在整合spingmvc的过程中,同样也是遇到了406的问题,前台ajax总是不能继续往下面执行,经过前台的检查元素,查看得知,状态码为406
如果当时没有在网上,查询结果,估计这个问题要困扰好久的。
在这里分享出来,虽然也是转载的,但是希望能够帮到更多的人解决这样的问题。
当时没有截图我自己的代码和错误提示,遇到这样问题的亲们,可以自行导包之后测试,我当时的错误就是没有导包造成的
如果亲们有其他的解决方法或者意见,请在下面留言,希望能帮到更多的人。
引起的原因:
由于设置了@ResponseBody,要把对象转换成json格式,缺少转换依赖的jar包,故此错。
解决办法:
加入依赖的jar,jackson-core-asl-1.9.12.jar,jackson-mapper-asl-1.9.12.jar问题解决。
jackson-mapper-asl-1.9.12.jar (762.1 KB)
jackson-core-asl-1.9.12.jar (226.8 KB)
相关文章推荐
- SpringMVC异常报406 (Not Acceptable)的解决办法
- SpringMVC异常报406 (Not Acceptable)的解决办法
- SpringMVC异常报406 (Not Acceptable)的解决办法
- SpringMVC异常报406 (Not Acceptable)的解决办法
- SpringMVC异常报406 (Not Acceptable)的解决办法
- SpringMVC异常报406 (Not Acceptable)的解决办法
- SpringMVC异常报406 (Not Acceptable)的解决办法
- Spring Boot 406(type=Not Acceptable, status=406)异常解决办法
- SpringMvc406(Not Acceptable)的解决办法
- gMVC异常报406 (Not Acceptable)的解决办法
- SpringMVC异常报406的解决办法
- SpringMVC ajax 请求报错:406 Not Acceptable 的解决办法 使用@ResponseBody注解
- springMvc中406错误解决,springMvc使用json出现406 (Not Acceptable)
- 解决SpringMvc返回json报Response 406 Not Acceptable
- springmvc 页面400异常,访问不到controller原因及解决办法
- SpringMVC:解决406 not acceptable
- Spring MVC json问题(406 Not Acceptable) 解决办法
- springmvc+ajax实现省市区三级联动以及406 (Not Acceptable)的解决办法
- SpringMVC出现406错误的解决办法
- springmvc返回json数据406错误的解决办法