IE浏览器请求json数据弹出下载框问题

IE浏览器下输入地址如:http://localhost/xx/getJson.do获取json数据

这时弹出下载窗口

解决方法:

修改服务器响应头:Content-Type:text/html;charset=UTF-8

Java代码:

resp.setContentType("text/html;charset=UTF-8");

如果之前是application/json的话就会弹出下载窗口.


如果使用springmvc返回json的话可以做如下设置:

<mvc:annotation-driven>	   
        <mvc:message-converters>  
            <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">  
                <property name="supportedMediaTypes">  
		            <list>		                
		                <value>text/html;charset=UTF-8</value><!-- 避免IE出现下载JSON文件的情况 -->  
		            </list>  
        		</property>  
                <property name="objectMapper">  
                    <bean class="com.fasterxml.jackson.databind.ObjectMapper">
                    	<!-- 处理responseBody 里面日期类型 -->  
                        <property name="dateFormat">  
                            <bean class="java.text.SimpleDateFormat">  
                                <constructor-arg type="java.lang.String" value="yyyy-MM-dd HH:mm:ss" />  
                            </bean>  
                        </property> 
                        <!-- 为null字段时不显示 -->
                        <property name="serializationInclusion">
                            <value type="com.fasterxml.jackson.annotation.JsonInclude.Include">NON_NULL</value>
                        </property> 
                    </bean>  
                </property>  
            </bean>  
        </mvc:message-converters>  
</mvc:annotation-driven>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值