我的代码如下:package com.strut2.download;import java.io.InputStream;import javax.servlet.ServletContext;import org.apache.struts2.ServletActionContext;import com.opensymphony.xwork2.ActionSupport;public class DownLoadAction extends ActionSupport { public InputStream getInputStream()
{
System.out.println("------------------------");
//getResourceAsStream中的字符串参数代表的是什么意思?,是文件的所在路径吗?还是服务器端文件的所在位置呀
return ServletActionContext.getServletContext().getResourceAsStream("F:/JAVA/Struts2/WebRoot/upload/Struts2.ppt");
} @Override
public String execute() throws Exception {
return SUCCESS;
}


}配置文件内容为: <action name="download" class="com.strut2.download.DownLoadAction">
<result name="success" type="stream">
<param name="contentType">application/vnd.ms-powerpoint</param>
<param name="contentDisposition">filename="Struts2.ppt"</param>
<param name="inputName">inputStream</param> 
</result>
</action>jsp页面的内容为:<s:a href="/LoginTest/download.action">下载</s:a>
报的错误为:
2009-5-26 18:00:36 org.apache.struts2.dispatcher.StreamResult doExecute
严重: 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.   

    return ServletActionContext.getServletContext().getResourceAsStream("F:/JAVA/Struts2/WebRoot/upload/Struts2.ppt"); 这个路径必须是这个项目里面的根路径  它是般指在Tomcat 6.0\webapps\项目名称\WebRoot\upload下面
    所以得改成
    /upload/Struts2.ppt
      

  2.   

    getResourceAsStream这是java加载资源的方法,所谓资源,实际上是任何一个文件,但特别的是,getResourceAsStream这个方法不使用绝对路径,
    而是使用相对于classpath环境变量的相对路径。所以,如果写:
    getResourceAsStream("/resource.xml");
    则要保证classpath下有resource.xml文件就能找到。通常,开发环境下,src目录(也就是源代码所在的目录)是包含在classpath中的,
    而在tomcat下,classpath其一指向:WEB-INF/classes目录。
      

  3.   

    相对WEB-INF/classes的路径,如:
    "/config.properties" 表示"WEB-INF/classes/config.properties"下的;
    "/com/test/config.properties" 表示"WEB-INF/classes/com/test/config.properties"这种用法是很有好处的,如果你的包要打成jar,里面又要引用到某些资源(如图片、tld文件或其它配置文件),那么把你的资源放在src目录下就能保证所用的资源也会被打包进去,这样可以做到移植的时候资源和项目路径无关,从而不用改动任何代码。
      

  4.   

    还是不懂怎么则要保证classpath下有resource.xml文件就能找到?怎么配?