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

Can not find a java.io.InputStream with the name [inputStream] in the invocation stack. Check the <p

2016-03-20 17:45 501 查看
关于stuts的下载文件问题具体异常: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. 就是这个问题,从一点多纠结了,几个小时,查了好多资料,也没查到。请看:事情是这样的、、、、、、、、、、、1文件路径不对,根本就没有取到文件。这种情况下,可以将获得InputStream的那条语句放在system.out.println()中输出一下,若为null,那就是路径不对了,或者说得准确些就根本没有找到文件。2.在action中没有写配置文件中"<param name="inputName">"后面属性的那个get方法.3.而当属性写错时,也会出现这样情况,<param name="inputName">inputStream</param>和private InputStream inputStream;必须要一致
public String getContentType() {
return contentType;
}
public void setContentType(String contentType) {
this.contentType = contentType;
}
public long getContentLength() {
return contentLength;
}
public void setContentLength(long contentLength) {
this.contentLength = contentLength;
}
public String getContentDispostion() {
return contentDispostion;
}
public void setContentDispostion(String contentDispostion) {
this.contentDispostion = contentDispostion;
}<pre name="code" class="java">
public InputStreamgetInputstraam() {return inputStream;}
而我的配置文件是
<action name="testDowload"class="com.zhu.cn.dowload.DowloadAction"><!-- 可以实现上传与下载功能 --><result name="success" type="stream"><span style="background-color: rgb(255, 0, 0);"> <param name="inputName">inputStream</param></span><param name="contentType">application/octet-stream</param>                 <param name="contentDisposition">filename="main111222.css"</param><param name="bufferSize">2048</param></result></action>
就是这个问题,就因为我的粗心,造成的。而
<span style="background-color: rgb(255, 0, 0);"><span style="font-size:18px;">inputStream 必须</span><span style="font-size: 18px;">和</span></span><strong style="font-size: 12px; font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"><span style="font-size:18px;"></span></strong><div style="display: inline !important;"><pre name="code" class="html" style="display: inline !important;"><span style="background-color: rgb(255, 0, 0);"></span><pre name="code" class="java" style="display: inline !important;"><span style="background-color: rgb(255, 0, 0);">Inputstraam一致  </span>
<span style="font-size:18px;">	public String execute() throws Exception {// TODO Auto-generated method stub//ServletContext  servletcontent=ServletActionContext.getServletContext();//  String dir=servletcontent.getRealPath("/file/"+pptFileName);contentDisposition="attachment;filename=bb.html";ServletContext servletcont=ServletActionContext.getServletContext();System.out.println("路径"+servletcont);String filename=servletcont.getRealPath("/file/bb.html");System.out.println(filename);//filename=new String(filename.getBytes("UTF-8"),"ISO8859-1");// System.out.println(filename);inputStream=new FileInputStream(filename);System.out.println(inputStream);if(inputStream==null){System.out.println("空值");}contentLength = inputStream.available();System.out.println(contentLength);return SUCCESS;}</span>
具体的配置都在这里,这样就可以进行文件的下载,jspsmart .jar可以进行文件下载,现在也可以用stuts实现文件传输。另外写代码一定要规范,否则,一点小熊错,可能导致你全盘皆输,今天就是血的教训。。。。。。。。。。。。。。。。。。。。。。。。。。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: