请会struts2实现下载的高手来看看,这是什么问题,急,实现下载是我的任务,求高手指点啊,这对我很重要

下面是我的代码,求高手指点,我试了很久,就是不行,请高手来帮我看看这是什么原因,到底错在哪里了,path我给的是绝对地址,相对地址我也试了,但是inputstream一直为null,想不通了,有没有大神会,struts2实现下载的,会的可以写个类似的案例给我参考一下,在下不胜感激!--------------------------------------struts2实现下载出现的问题-----------------------------------------java.lang.IllegalArgumentException: Can not find a java.io.InputStream with the name [targetFile] in the invocation stack. Check the <param name="inputName"> tag specified for this action.----------------------------DownLoad类--------------------------------------------------public class DownLoad { public InputStream getDownLoadFile(String path){ InputStream is = ServletActionContext.getServletContext() .getResourceAsStream(path); return is; }}---------------------------------------action----------------------------------------------public class DownLoadAction { //input private String path; //output private InputStream downloadFile; get、set.............. public String execute(){ DownLoad dl = new DownLoad(); downloadFile = dl.getDownLoadFile(path); return "success"; }}------------------------------------struts配置-------------------------------------------- <action name="down" class="com.plm.action.DownAction"> <result name="success" type="stream"> <!-- 下载文件类型定义 --> <param name="contentType">text/plain</param> <!-- 下载文件处理方法 --> <param name="contentDisposition"> attachment;filename="file" </param> <!-- 下载文件输出流定义 --> <param name="inputName">downloadFile</param> <!-- 缓存大小 --> <param name="bufferSize">4096</param> </result> </action>
2026年09月28日 05:40
有1个网友回答
网友(1):

InputStream is = ServletActionContext.getServletContext()
.getResourceAsStream(path);

你可以调试一下,你的这个is得到的应该是null
是不是你的path不对,仔细检查一下