`
wsxhbusbanana
  • 浏览: 32500 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

form+iframe上传文件返回json在IE下提示下载的问题(源于ueditor的错误)

阅读更多

     最近做系统的时候需要富文本编辑器,考察了很多,最后还是回头找ueditor亲密接触。至于如何将ueditor彻底放入我系统,而不是使用controller.jsp之类的文件转发的方式,将另起文章讨论。这里就遇到的单图上传返回json的时候IE提示下载的问题做解决方法的分析。我使用的是springmvc.

     现象:多图上传成功,但单图上传成功后直接图片不回显,IE提示下载upload.do文件(实际是我后台处理文件上传的class),且consol报系统连续运行后台上传文件处理方法三次,第一次成功后绑定request上下文再运行两次。

     结论:IE10以下版本对application/json类型数据支持力度不够,近几年直接返回json越来越流行,才导致各大浏览器通吃json,早期版本并不支持,直接就提示下载或保存。

     解决方法:在web.xml配置DispatcherServletd时指定的文件中(我指定的是spring-mvc.xml)加上返回对象时自动解析为json的配置:

 <!-- 避免IE在ajax请求时,返回json出现下载 此处配置与<context:annotation-config /><mvc:annotation-driven>配合使用效果一样-->
   <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"	p:ignoreDefaultModelOnRedirect="true" >
   		<property name="messageConverters">	
   			<list>					
   				<bean id="jacksonMessageConverter" 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>
			    </bean>	
   			</list>			
   		</property>		
   	</bean>

 然后运行完美了。实际上这里的意思是用jackson自动将返回的各种对象转换成json。

         其实这个配置和<context:annotation-config /><mvc:annotation-driven/>配合使用效果一样的,如果还想使用jackson解析,那么可以这么写

 

<context:annotation-config /> 
<mvc:annotation-driven>
   	<mvc:message-converters register-defaults="true">			
   		<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" p:supportedMediaTypes="*/*" />		
   	</mvc:message-converters>
</mvc:annotation-driven>

 这就更简练了。

  实际上这俩是一样的,在<context:annotation-config />加载的时候会加载一些spring自己的东西,其中就有  org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter,所以意思是一样的。

这样配置了之后,ueditor使用,以及在form下隐藏iframe提交文件的时候返回json运行就很好了。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics