码迷,mamicode.com
首页 > 编程语言 > 详细

Spring4 MVC json问题(406 Not Acceptable)

时间:2014-08-03 12:56:15      阅读:285      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   使用   os   io   文件   

    为了配合ECS 把原来房子BAE中的代码重新构建,发现发送JSON数据与EXTJS不配合,找了很久发现CSDN上有篇文章正好解决了,庆幸有互联网。

    用的是第二中方法

原帖:http://blog.csdn.net/woshiwanxin102213/article/details/37521303


最近使用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配置文件添加:

    <mvc:annotation-driven/>

<!-- 避免IE执行AJAX时,返回JSON出现下载文件 -->  
    <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转换器 -->  
            </list>  
        </property>  
    </bean>


解决方法二:

1、导入第三方的fastjson包,fastjson-1.1.34.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>


Spring4 MVC json问题(406 Not Acceptable),布布扣,bubuko.com

Spring4 MVC json问题(406 Not Acceptable)

标签:style   blog   http   color   使用   os   io   文件   

原文地址:http://my.oschina.net/xldc/blog/297506

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!