日期:2014-05-17  浏览次数:20552 次

使用struts2下载文件
最近在使用struts2实现下载文件,可是总是显示inputstream这个参数在栈中找不到,但是在配置文件中已经配置过了,action中也有get方法,将代码单独拿出来放在一个项目中就可以正常运行,但是一旦放到整个项目中就不行了,这是怎么回事?
struts2 文件下载

------解决方案--------------------
一般这样ServletActionContext.getServletContext().getResourceAsStream()
看看你的action
------解决方案--------------------
你有实现对应的拦截器吗?!
for example:

<action name="upload" class="com.jungle.action.PostAction">
<interceptor-ref name="fileUpload">
<param name="maximumSize">5242880</param><!--单个文件 5兆-->
</interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
<result name="upLoad">
/back/postManage/uploadSuccess.jsp
</result>  
<!-- 下载 -->
<result name="download" type="stream">
<param name="contentDisposition">
attachment;filename="${newname}"
</param>
<param name="bufferSize">1024</param>
<!--<param name="inputName">inputStream</param>-->
</result>
</action>