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

struts2 文件下载问题 Can not find a java.io.InputStream with the name [downloadFile]
严重: Can not find a java.io.InputStream with the name [downloadFile] in the invocation stack. Check the <param name="inputName"> tag specified for this action.

------解决方案--------------------
楼主看看上传到tomcat里面的文件是不是没有了? 楼主如果在eclipse中重启了tomcat 的话,tomcat会自动清空上传到项目下面的文件的,这样你去下载的话肯定是找不到的。
如果你上传到服务器之后,立刻进行下载,是可以下载的,重启服务器再点击下载的话,就会报你那个错了。

------解决方案--------------------
会不会是中文乱码的问题
建议排除上传路径中的中文编码,然后再测试下,是否还会出现类似错误
------解决方案--------------------
public InputStream getDownloadFile()
{
this.setFileName();
return ServletActionContext.getServletContext().getResourceAsStream(
"/"+UploadConfigurationRead.getInstance().getConfigItem("uploadFilePath").trim()+"/" + fileName);
}
改成:

public InputStream getDownloadFile throws FileNotFoundException(){
this.setFileName();
File file = new File("/"+UploadConfigurationRead.getInstance().getConfigItem("uploadFilePath").trim()+"/" + fileName);
InputStream is = new FileInputStream(file);
return is;
}
就行了