zoukankan      html  css  js  c++  java
  • jsckson,想说爱你不容易啊。。。406错误

    最近使用spring4.0的Mvc,json请求时,客户端报错,406 Not Acceptable

    解决方法一:

    1、导入第三方的jackson包,jackson-mapper-asl-1.9.7.jar和jackson-core-asl-1.9.7.jar。

    2、spring配置文件添加:

    [html] view plain copy
     在CODE上查看代码片派生到我的代码片
    1. <mvc:annotation-driven/>  
    2.   
    3. !-- 避免IE执行AJAX时,返回JSON出现下载文件 -->    
    4. <bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">    
    5.     <property name="supportedMediaTypes">    
    6.         <list>    
    7.             <value>text/html;charset=UTF-8</value>    
    8.         </list>    
    9.     </property>    
    10. </bean>    
    11.   
    12. <!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->    
    13. <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">    
    14.     <property name="messageConverters">    
    15.         <list>    
    16.             <ref bean="mappingJacksonHttpMessageConverter" /><!-- json转换器 -->    
    17.         </list>    
    18.     </property>    
    19. </bean>   


    解决方法二:

    1、导入第三方的fastjson包,fastjson-1.1.34.jar

    2、Spring配置文件添加:

    [html] view plain copy
     在CODE上查看代码片派生到我的代码片
    1. <mvc:annotation-driven>  
    2.     <mvc:message-converters register-defaults="true">  
    3.         <!-- 避免IE执行AJAX时,返回JSON出现下载文件 -->  
    4.         <bean id="fastJsonHttpMessageConverter" class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">  
    5.             <property name="supportedMediaTypes">  
    6.                 <list>  
    7.                     <value>application/json;charset=UTF-8</value>  
    8.                 </list>  
    9.             </property>  
    10.         </bean>  
    11.     </mvc:message-converters>  
    12. </mvc:annotation-driven>  
  • 相关阅读:
    dedecms图片列表效果调用
    ThinkPHP 中M方法和D方法的具体区别
    在线更新dede程序后 网站出现错误 DedeCMS Error:Tag disabled:"php" more...!
    Form元素示例
    PHP使用frameset制作后台界面时,怎样实现通过操作左边框架,使右边框架中的页面跳转?
    删除UTF-8 BOM头的GUI小工具
    解决 ultraedit 菜单字体模糊
    git使用及一些配置、问题
    shell之基本语法
    shell之iptables
  • 原文地址:https://www.cnblogs.com/15linzhijie/p/6120345.html
Copyright © 2011-2022 走看看