您的位置:首页 > 编程语言 > Java开发

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

2016-09-26 15:33 309 查看
转自:http://blog.csdn.net/sapphire_aling/article/details/6715448

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

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);

这样就可以了

希望对有同样问题的朋友能有个帮助
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐