读书人

struts2 下载文件报错的有关问题

发布时间: 2013-09-11 17:20:06 作者: rapoo

struts2 下载文件报错的问题

2010-1-22 9:45:03 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.
2010-1-22 9:45:03 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 [inputStream] in the invocation stack. Check the <param name="inputName"> tag specified for this action.
at org.apache.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)

==========================解决办法===========================
这个错误报的真有点误导人呀,我还一直以为我struts.xml中<param name="inputName">inputStream</param>和action中的方法名getInputStream()不一致的问题,大家如果也碰到此类问题,直接打印
InputStream in=ServletActionContext.getServletContext().getResourceAsStream(realPath);
System.out.println(in);

如果打印为NULL的话,恭喜您,问题得以解决,问题的原因是这个流的realPath路径错误,像我的,
//??String realPath=ServletActionContext.getServletContext().getRealPath("/uploadImages")+ "/"+name; 路径错误


我的异常网推荐解决方案:Servlet.service() for servlet default threw exception,http://www.myexception.cn/eclipse/181756.html

读书人网 >软件架构设计

热点推荐