ajax返回失败406,前端控制台返回406错误解决方法(示例代码)
问题描述:406 NotAcceptable,message:description The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" header.
问题描述:
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
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐



所有评论(0)