SpringMvc JSON 406,吐血。。。。
解决方法一:
1、导入jackson-core-2.5.1.jar和jackson-databind-2.5.1.jar
2、Spring配置文件添加:
1 spring3为:org.springframework.http.converter.json.MappingJacksonHttpMessageConverter
spring4为:org.springframework.http.converter.json.MappingJackson2HttpMessageConverter <bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<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转换器 这里可以直接转换成json数据-->
</list>
</property>
</bean>
------------------------------------------------------------------------------
<bean id="stringConverter" class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html; charset=UTF-8</value>
</list>
</property>
</bean>
<bean id="jsonConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"></bean>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="stringConverter"/>
<ref bean="jsonConverter"/><!-- 这里出来的object-->
</list>
</property>
</bean>
虚线下面和上面的区别在于有没有加StringHttpMessageConverter以及有没有为MappingJacksonHttpMessageConverter加上property 属性,不加property 属性的话,页面不会显示undefined,会显示对象属性的值。
解决方法二:
1、导入第三方(阿里巴巴)的fastjson包,fastjson-1.2.7.jar
2、Spring配置文件添加:
<mvc:annotation-driven>
<mvc:message-converters register-defaults="true">
<!-- 避免IE执行AJAX时,返回JSON出现下载文件 -->
<bean id="fastJsonHttpMessageConverter" class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
SpringMvc JSON 406,吐血。。。。的更多相关文章
- springmvc json 406
spring 4.0 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="ht ...
- springMvc中406错误解决,springMvc使用json出现406 (Not Acceptable)
springMvc中406错误解决, springMvc使用json出现406 (Not Acceptable) >>>>>>>>>>> ...
- springmvc报406错误
springmvc出现406,无非就两种情况,第一,百分之九十是json包没加进来,第二,百分之十,就是@ResponseBody返回的的数据,在请求的URL中不能有 .html的后缀
- springmvc遇见406错误的问题分析
如果springmvc遇到406错误: 90%没有加入Jackson的包 10%因为后缀为.html 10%的情况,解决方案为加多一个映射,使用.action
- springMVC+json构建restful风格的服务
首先.要知道什么是rest服务,什么是rest服务呢? REST(英文:Representational State Transfer,简称REST)描写叙述了一个架构样式的网络系统.比方 web 应 ...
- 关于springmvc json交互产生的406错误
产生错误的背景:springmvc使用<mvc:annotation-driven>进行配置,那么只要引入响应的json解析包就可以了.在pom中已经引入了如下: <dependen ...
- springmvc+json
1.在写我的springmvc demo时,由于要向前台返回相关信息,于是设置了@ResponseBody,但是要把对象转换成json格式,我却没有在xml文件里配置,所以报如下错误:HttpMedi ...
- SpringMvc Json LocalDateTime 互转,form urlencoded @ModelAttribute 转换
JDK8 的LocalDate 系列日期API ,比Date 或者 Calendar 都好用很多,但是在SpringMvc 自动装配会有点小问题 会导致抛出类似异常 default message [ ...
- SpringMVC @ResponseBody 406
使用@ResponseBody注解可以让Controller返回json格式的数据,在需要传输一个对象信息的时候往往使用这种方式.如果在使用的时候遇到了406,一般原因是: 缺少jar包.转换成jso ...
随机推荐
- easyUI中datetimebox和combobox的取值方法
easyUi页面布局中,查询条件放在JS中,如下 <script type="text/javascript"> var columnList = [ [ { ...
- 【转】最佳Restful API 实践
原文转自:https://bourgeois.me/rest/ REST APIs are a very common topic nowaday; they are part of almost e ...
- ArrowLayer : A coustom layer animation
Since my other answer (animating two levels of masks) has some graphics glitches, I decided to try r ...
- NueGet设置package Source
package Source为:http://packages.nuget.org/v1/FeedService.svc/ 最新的地址(2015-4-10):https://www.nuget.org ...
- 开篇----JavaScript细节的那些事儿
JavaScript现在已经是全世界浏览器通用的语言,目前也完全可以在服务器端做开发,如Node.js,市面上好的JavaScript的书有很多,有的还是经典之作,值得收藏. 趁此东风,打算接下来写一 ...
- 收拾那掉了一地的session
多个页面有如下多个session,本来可能是如下面这样的 Session["UId"] = 10; Session["UName"] = "test& ...
- 总结C#保留小数位数及百分号处理
方法一: ); 方法二: Math.Round() 方法三: double dbdata = 0.55555; string str1 = dbdata.ToString("f2" ...
- js jquery实时计算输入字符
在项目中需要倒还可以输入多少字符
- Java设计模式(三) 抽象工厂模式
原创文章,同步发自作者个人博客,转载请注明出处 http://www.jasongj.com/design_pattern/abstract_factory/ 抽象工厂模式解决的问题 上文<工厂 ...
- java.nio.ByteBuffer中flip,rewind,clear方法的区别
对缓冲区的读写操作首先要知道缓冲区的下限.上限和当前位置.下面这些变量的值对Buffer类中的某些操作有着至关重要的作用: limit:所有对Buffer读写操作都会以limit变量的值作为上限. p ...