SpringMVC @ResponseBody在IE8变下载

来源:互联网 发布:js透明度渐变 编辑:程序博客网 时间:2024/06/01 09:52

在使用IE8请求用@ResponseBody注解返回json格式数据的action时自动变下载页面,火狐和chorme正常。其原因就是响应Content-Type的值为application/json;charset=UTF-8时,IE下会自动变成下载。

查看服务器响应头信息可通过firefox或Fiddler软件
Fiddler截获响应信息如下图
这里写图片描述

解决方法就是修改springMvc.xml配置,调整supportedMediaTypes中值的顺序,优先返回text/html;charset=UTF-8
附配置如下图

<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">    <property name="supportedMediaTypes">        <list>            <value>text/html;charset=UTF-8</value>            <value>application/json;charset=UTF-8</value>        </list>    </property>    <property name="objectMapper">        <bean class="org.codehaus.jackson.map.ObjectMapper">            <property name="serializationInclusion">                <value type="org.codehaus.jackson.map.annotate.JsonSerialize$Inclusion">NON_NULL</value>            </property>        </bean>    </property></bean>
2 2