struts2中文件下载迅雷显示后缀名为action的解决办法

     最近在使用struts2做一个导出excel文件的时候出现了一些问题,用IE等浏览器下载的时候是正常的,但是使用360,迅雷下载的时候会得到一个action文件,网上搜了下也没什么好的解决办法。不过wxinpeng提供了一个可以解决的办法,试了下果然可以。做下笔记。

    1、首先在web.xml中的struts2配置中加上一个其它扩展名的拦截

<filter>
		<filter-name>struts2</filter-name>
		<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
	</filter>
	<filter-mapping>  
        <filter-name>struts2</filter-name>  
        <url-pattern>*.xls</url-pattern>  
    </filter-mapping> 
	<filter-mapping>
		<filter-name>struts2</filter-name>
		<url-pattern>*.action</url-pattern>
	</filter-mapping>

      2、在struts配置中加上如下的一句话

                         <constant name="struts.action.extension" value="action,htm,xls" /> 

     就可以了,其它action中的处理是不用变的。

猜你喜欢

转载自ifox.iteye.com/blog/1811010