spring4.1的Mvc,json请求时,客户端报错,406 Not Acceptable
解决方法一:
1、导入第三方的jackson包,
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.4.0</version>
</dependency>
2、Spring配置文件添加:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
<!--避免IE执行AJAX时,返回JSON出现下载文件-->
< bean id = "mappingJacksonHttpMessageConverter" class = "org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" >
< property name = "supportedMediaTypes" >
< list >
< value >text/html;charset=UTF-8</ value >
</ list >
</ property >
</ bean >
<!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 --> < bean class = "org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" >
< property name = "messageConverters" >
< list >
< ref bean = "mappingJacksonHttpMessageConverter" /> <!-- json转换器 --> </ list >
</ property >
</ bean > 本文转自yunlielai51CTO博客,原文链接:http://blog.51cto.com/4925054/1641926,如需转载请自行联系原作者
|