struts2 下载文件报错的问题

2010-1-22 9:45:03 org.apache.struts2.dispatcher.StreamResult doExecute

严重:Cannotfindajava.io.InputStreamwiththename[inputStream]intheinvocationstack.Checkthe<paramname="inputName">tagspecifiedforthisaction.

2010-1-229:45:03org.apache.catalina.core.StandardWrapperValveinvoke

严重:Servlet.service()forservletdefaultthrewexception

java.lang.IllegalArgumentException:Cannotfindajava.io.InputStreamwiththename[inputStream]intheinvocationstack.Checkthe<paramname="inputName">tagspecifiedforthisaction.

atorg.apache.struts2.dispatcher.StreamResult.doExecute(StreamResult.java:189)

atorg.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:178)

atcom.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:348)

atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:253)

atcom.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221)

==========================解决办法===========================

这个错误报的真有点误导人呀,我还一直以为我struts.xml中<paramname="inputName">inputStream</param>和action中的方法名getInputStream()不一致的问题,大家如果也碰到此类问题,直接打印

InputStreamin=ServletActionContext.getServletContext().getResourceAsStream(realPath);

System.out.println(in);

如果打印为NULL的话,恭喜您,问题得以解决,问题的原因是这个流的realPath路径错误,像我的,

//StringrealPath=ServletActionContext.getServletContext().getRealPath("/uploadImages")+"/"+name;路径错误

相关推荐