IE浏览器请求json数据弹出下载框问题【在springmvc中配置如下内容,可以避免】

来源:互联网 发布:传奇数据库下载 编辑:程序博客网 时间:2024/05/19 10:40

http://blog.csdn.net/thc1987/article/details/48240471


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

这时弹出下载窗口

解决方法:

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

Java代码:

[java] view plaincopy
  1. resp.setContentType("text/html;charset=UTF-8");  

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


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

[html] view plaincopy
  1. <mvc:annotation-driven>        
  2.         <mvc:message-converters>    
  3.             <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">    
  4.                 <property name="supportedMediaTypes">    
  5.                     <list>                          
  6.                         <value>text/html;charset=UTF-8</value><!-- 避免IE出现下载JSON文件的情况 -->    
  7.                     </list>    
  8.                 </property>    
  9.                 <property name="objectMapper">    
  10.                     <bean class="com.fasterxml.jackson.databind.ObjectMapper">  
  11.                         <!-- 处理responseBody 里面日期类型 -->    
  12.                         <property name="dateFormat">    
  13.                             <bean class="java.text.SimpleDateFormat">    
  14.                                 <constructor-arg type="java.lang.String" value="yyyy-MM-dd HH:mm:ss" />    
  15.                             </bean>    
  16.                         </property>   
  17.                         <!-- 为null字段时不显示 -->  
  18.                         <property name="serializationInclusion">  
  19.                             <value type="com.fasterxml.jackson.annotation.JsonInclude.Include">NON_NULL</value>  
  20.                         </property>   
  21.                     </bean>    
  22.                 </property>    
  23.             </bean>    
  24.         </mvc:message-converters>    
  25. </mvc:annotation-driven>  

===================================方法二:以下设置未测试,==================================================

http://www.jb51.net/article/50209.htm

今天遇到Jquery 返回json数据,IE浏览器提示下载的问题,当提交完数据后返回的本来是json数据的,在火弧里测试正常,但是IE里老是提示保存,在网上搜索了下,大部分是说将ContentType设置为"text/xml“本人测试了下,返回值为undefined, 

原返回值设定:context.Response.ContentType = "application/json"; 

尝试: context.Response.ContentType = "text/xml;"; 失败 

后来试了下:context.Response.ContentType = "text/plain;charset=UTF-8"; 

成功!



===================================iis服务器配置参考下面文章=======================================

http://blog.csdn.net/kissdeath/article/details/20712153













0 0
原创粉丝点击