IE浏览器,进行文件上传下载rseponseBody返回json弹出下载框,原因在于ie浏览器不能识别
application/json;charset=UTF-8类型json
首先了解概念
text/html & text/plain的区别
Content-Type:用于定义用户的浏览器或相关设备如何显示将要加载的数据,或者如何处理将要加载的数据
MIME:MIME类型就是设定某种扩展名的文件用一种应用程序来打开的方式类型,当该扩展名文件被访问的时候,浏览器会自动使用指定应用程序来打开。多用于指定一些客户端自定义的文件名,以及一些媒体文件打开方式。
text/html的意思是将文件的content-type设置为text/html的形式,浏览器在获取到这种文件时会自动调用html的解析器对文件进行相应的处理。
text/plain的意思是将文件设置为纯文本的形式,浏览器在获取到这种文件时并不会对其进行处理。
解决:
方法一:从Java代码返回值入手
response.setContentType("text/html;charset=UTF-8");
PrintWriter writer=response.getWriter();
witer.writer("您要返回给前台的字符串")或者witer.print("您要返回给前台的字符串")
方法二:从spring配置文件入手
在applicationContext-mvc.xml文件添加如下:
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
<value>text/plain;charset=UTF-8</value>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
</list>
</property>
<mvc:annotation-driven>
注意:该配置一定要放在<mvc:annotation-driven>之前,否则不能正常处理参数类型转换
方法三:从spring配置文件入手
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdater">
<property name="messageConverters">
<list>
<ref bean="mappingJackHttpMessageConverter">
</list>
</property>
</bean>
<bean id="mappingJackHttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
<value>text/plain;charset=UTF-8</value>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
分享到:
相关推荐
SpringMVC ---- HelloWorld ---- 代码 SpringMVC ---- HelloWorld ---- 代码 SpringMVC ---- HelloWorld ---- 代码 SpringMVC ---- HelloWorld ---- 代码 SpringMVC ---- HelloWorld ---- 代码 SpringMVC ---- Hello...
SpringMVC-Mybatis-Shiro-redis-master..............
基于SpringMVC Mybatis Shiro Redis 的权限管理系统,该系统已经部署到线上,线上访问地址:http://shiro.itboy.net,登录账号:admin 密码:sojson,,详细教程参考sojson.com/shiro
springmvc-framework-官方中文版
基于SpringMVC、Mybatis、Redis、Freemarker的Shiro管理Demo源码的升级版 相关详细配置说明请参看 --> http://www.sojson.com/shiro
这是一个springmvc-config.xml文件,<?xml version="1.0" encoding="UTF-8"?> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:...
JavaEE企业级开发-----SpringMVC实现 文件的上传下载实验报告
swagger-springmvc-1.0.2/swagger-springmvc-1.0.2-javadoc/swagger-springmvc-1.0.2-sources
使用即插即用的MultipartResolver实现文件上传功能,需要借助于Commons的CommonsMultipartResolver
SpringMVC-Activiti5.16-Shiro-EasyUI,以前CSDN有的资源找不到了,新上传一个
ssm-springMVC-整合Quartz(解决了无法注入service问题).doc
SpringMVC------从HelloWorld开始
springmvc文件上传下载。
springmvc-json-lib.rar springmvc-json-lib.rar
微信 java weixin-java-tools-springmvc-master 微信 java weixin-java-tools-springmvc-master
easyui的tree组件的使用,使用springmvc作为后台支持,前后通信是实现tree的操作
springmvc框架的文件上传 下载:自己整理的一些错误:404等
springMVC-myBaties整合,springMVC-myBaties整合springMVC-myBaties整合
SpringMVC框架实现文件的上传和下载项目案例源码
springmvc-without-webxml springmvc-without-webxmlspringmvc-without-webxml