问题描述:
406 Not Acceptable,message:description The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers ()错误。(说是指定的资源已经找到,但它的MIME类型和客户在Accpet头中所指定的不兼容)。
前后台代码经过排查都没有问题,本人在Spring mvc控制层用到了@ResponseBody标注,以便返回的数据为json格式的数据,到前端JS中用。而前端却需要text/html;charset=UTF-8这样的格式,导致的问题。
解决办法如下:
1.需要使用jackson,在pom.xml中引入jackson的依赖
org.codehaus.jackson
jackson-core-asl
org.codehaus.jackson
jackson-mapper-lgpl
1.9.12
2. spring-servlet.xml文件中配置转换的bean
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
text/html;charset=UTF-8
3.spring-servlet.xml文件的头部声明部分加入如下三行即可(因为util:list)
xmlns:util="http://www.springframework.org/schema/util"http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd