Failed to load resource: the server responded with a status of 406 (Not Acceptable)问题的解决方案
2017-01-18 22:58
651 查看
使用SpringMVC时,我们经常需要在Controller里返回一个对象,以json的方式传给视图。
可能会遇到如下问题:
Failed to load resource: the server responded with a status of 406 (Not Acceptable)
引发这问题的可能性有好几种,我遇到这个是因为json转换的问题。
我们在SpringMVC的配置文件中加上如下配置即可:
当然要引入相关的jar包,我这里使用的是maven,需要的依赖如下:
对应的jar包为:
jackson-mapper-asl-1.9.13.jar
jackson-core-asl-1.9.13.jar
jackson-annotations-2.6.3.jar
jackson-core-2.6.3.jar
jackson-databind-2.6.3.jar
如果用Maven下载包的时候太慢,可以直接使用我上传的资源:http://download.csdn.net/detail/lianjiww/9740986
把这个资源下载下来直接考到本地Maven仓库即可。
可能会遇到如下问题:
Failed to load resource: the server responded with a status of 406 (Not Acceptable)
引发这问题的可能性有好几种,我遇到这个是因为json转换的问题。
我们在SpringMVC的配置文件中加上如下配置即可:
<mvc:annotation-driven> <mvc:message-converters> <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter" /> <bean class="org.springframework.http.converter.FormHttpMessageConverter" /> <bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter" /> <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/> <bean class="org.springframework.http.converter.StringHttpMessageConverter"> <constructor-arg index="0" value="UTF-8" /> </bean> </mvc:message-converters> </mvc:annotation-driven>
当然要引入相关的jar包,我这里使用的是maven,需要的依赖如下:
<dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-mapper-asl</artifactId> <version>1.9.13</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-annotations</artifactId> <version>2.6.3</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.6.3</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.6.3</version> </dependency>
对应的jar包为:
jackson-mapper-asl-1.9.13.jar
jackson-core-asl-1.9.13.jar
jackson-annotations-2.6.3.jar
jackson-core-2.6.3.jar
jackson-databind-2.6.3.jar
如果用Maven下载包的时候太慢,可以直接使用我上传的资源:http://download.csdn.net/detail/lianjiww/9740986
把这个资源下载下来直接考到本地Maven仓库即可。
相关文章推荐
- springmvc获取json Failed to load resource: the server responded with a status of 406 (Not Acceptable)
- SprimgMVC:Failed to load resource: the server responded with a status of 406 (Not Acceptable)
- Failed to load resource: the server responded with a status of 406 (Not Acceptable)
- Spring MVC json报406错误的解决办法 Failed to load resource: the server responded with a status of 406
- failed to load resource the server responded with a status of 500 (internal server error)
- ajaxSubmit 报错 400 (Failed to load resource: the server responded with a status of 400 (Bad Request))
- Failed to load resource: the server responded with a status of 500 (Internal Server Error)
- PHP 中 Failed to load resource: the server responded with a status of 500 (Internal Server Error)
- Failed to load resource: the server responded with a status of 500 (Internal Server Error)
- 关于使用springmvc时Failed to load resource: the server responded with a status of 400 (Bad Request)错误可能原因
- 上传文件失败 Failed to load resource: the server responded with a status of 413 (Request Entity Too Large)
- jquery:Failed to load resource: the server responded with a status of 404 (Not Found)
- Failed to load resource: the server responded with a status of 404
- SrpingMVC==>Failed to load resource: the server responded with a status of 404(Not Found)
- SharePoint Debug - Failed to load resource: the server responded with a status of 500
- Failed to load resource: the server responded with a status of 405 (Method Not Allowed)
- Failed to load resource: the server responded with a status of 500 ()
- springmvc Failed to load resource: the server responded with a status of 404 (Not Found)
- Failed to load resource: the server responded with a status of 400 (Bad Request)
- ripple Failed to load resource: the server responded with a status of 404 (Not Found)