大家帮忙看看这个问题怎么解决?非常感谢!(I)这是Tomcat报的exception: 
2010-3-29 16:11:26 com.opensymphony.xwork2.util.logging.commons.CommonsLogger error
严重: 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.
(II)这是浏览器报的exception: 
Struts has detected an unhandled exception: Messages: Can not find a java.io.InputStream with the name [targetFile] in the invocation stack. Check the tag specified for this action. 
 
File: org/apache/struts2/dispatcher/StreamResult.java 
Line number: 237 
(III)这是我的struts.xml
<package name="download" extends="struts-default">
     <action name="download" class="org.struts2.Upload.FileDownloadAction">
     <param name="inputPath">\files\abc.jpg</param>
     <result name="success" type="stream">
     <param name="contentType">image/jpg</param>
     <param name="inputName">targetFile</param>
     <param name="contentDisposition">filename="abc.jpg"</param>
     <param name="bufferSize">4096</param>
     </result>
</action>
</package>
(IV)这是我的Action:
package org.struts2.Upload;import java.io.InputStream;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;public class FileDownloadAction extends ActionSupport{
private String inputPath; public void setInputPath(String value) {
inputPath = value;
}

public InputStream getTargetFile() throws Exception {
return ServletActionContext.getServletContext().getResourceAsStream(inputPath);
}
}
(V)HTML中的链接:
<h3>文件下载</h3>
    <ul>
     <li><a href="download.action">点此下载</a></li>
    </ul>(VI)web.xml是没有问题的。

解决方案 »

  1.   

    extends ActionSupport 这个类是你自己写的吗,struts中没有这个
      

  2.   

    我用的是struts2.1.8它里面有这个类,里面已经包含了execute方法,并且定义了很多实用的方法
      

  3.   

    Check the <param name="inputName"> tag specified for this action.没这个inputName属性啊,提示很明显,叫在这个ACTION中声明一个inputName属性,并且需要SET,GET方法我们点击下载的时候,ACTION把路径传给inputName属性的SET方法,下载的信息流会到GET方法里找到你在配置文件中给inputName属性指定的参数啊,你没inputName属性,你叫ACTION去哪找....
      

  4.   

    看来你不会用Struts2啊
    你在页面传过来的参数
    需要Action的类中有对应匹配类型并且名字完全一致的参数与之对应的
    并且需要set和get方法
    如果你没有
    你点击页面的那些东西
    根本没用的你的ActionSupport类看起来好奇怪啊
      

  5.   

    下面我回复一下6楼的朋友并且简述一下<param name="inputName">targetFile</param>这个标签对:struts.xml是没有问题的,这个和文档中的描述一至。
    TargetFile在Action中有get方法:
    public InputStream getTargetFile() throws Exception {
    return ServletActionContext.getServletContext().getResourceAsStream(inputPath);
    }
    我在一本书中看到TargetFile要写成targetFile即首字母小写。
    struts2的文档中说inputName的默认值是inputStream
      

  6.   

    我刚刚也在弄这个,弄了半天,发现我把图片的位置放错了,因为开始在写上传的,写下载的时候就用了上传的文件,根本没注意这个文件夹没在当前工程中。呵呵看了下你的好像没哪里有问题哦,你看看是不是文件位置没放好。出现这问题是ServletActionContext.getServletContext().getResourceAsStream(path);为null,一般就是路径问吧!!!呵呵,我也是初学者,看见是29号的就回下
      

  7.   

    我就是在MyEclipse项目的根目录中新建了一个文件夹名叫files,里面放了一张图片名叫abc.jpg。
    那这样写<param name="inputPath">\files\abc.jpg</param>路径好像没问题吧。
      

  8.   

        <param name="inputPath">\files\abc.jpg</param>
      要在tomcat的目录下建立一个文件夹名叫files。
      

  9.   

    我用的eclipse,tomcat 下没有 我的项目,我的项目在项目工作空间里,我的下载文件在项目文件夹里,为什么我的问题和楼主的一样啊,楼主的问题解决没,给小弟分享一下吧!