文件下载Can not find a java.io.InputStream with the name [inputStream] in the invocation stack错误

来源:互联网 发布:java windowbuilder 编辑:程序博客网 时间:2024/05/29 17:24

今天实现文件下载功能,照着网上的代码写了,结果总是提示下面的错误:

Can not find a java.io.InputStream with the name [inputStream] in the invocation stack. Check the <param name="inputName"> tag specified for this action.

这个错误,这个错误网上的解释都是正确的,就是输入流得到的是空

网上的得到输入流都是用这句话实现: inputStream=ServletActionContext.getServletContext().getResourceAsStream(realPath);

这里正常解释是相对路径realPath要以/开头,而且要下载的文件要位于Webcontent目录下

不过在我这里就是行不通

因此我放弃了相对路径,改成绝度路径实现

        String realPath = "d:\\Aggressive\\" + uploadFileName;
File file = new File(realPath);
inputStream = new FileInputStream(file);
这样就可以了

希望对有同样问题的朋友能有个帮助



原创粉丝点击