struts 文件上载(上载硬盘下文件方法)

struts 文件下载(下载硬盘上文件方法)
错误:
严重: Can not find a java.io.InputStream with the name [photoStream] in the invocation stack. Check the <param name="inputName"> tag specified for this action.
2008-4-17 17:04:44 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet default threw exception
java.lang.IllegalArgumentException: Can not find a java.io.InputStream with the name [photoStream] in the invocation stack. Check the <param name="inputName"> tag specified for this action.
        at org.apache.struts2" onclick="tagshow(event)" class="t_tag">struts2.dispatcher.StreamResult.doExecute(StreamResult.java:189)
        at org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:178)
        at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:348)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:253)
        at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221)
        at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
        at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
        at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
        at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)


问题所在:
第二,对ServletContext的getResourceAsStream方法理解有误,该方法不是从本地路径取文件,而是从web application的路径取文件流。

而且在return行前调用ServletActionContext.getServletContext().getResourceAsStream(path)应该可以发现是空指针

解决方法:

File file = new File(inputPath);
InputStream is= new FileInputStream(file);