struts2檔案下載出現Can not find a java.io.InputStream with the name的錯誤
JavaApacheServlet
今天在用struts2就行檔案下載時出現如下錯誤:
Java代碼
- Servlet.service() for servlet default threw exception
- java.lang.IllegalArgumentException: Can not find a java.io.InputStream with the name [imageStream] 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.best.top.validate.TopInterceptor.intercept(TopInterceptor.java:47)
- 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)
- at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
- at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:50)
- at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:504)
- at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
Servlet.service() for servlet default threw exceptionjava.lang.IllegalArgumentException: Can not find a java.io.InputStream with the name [imageStream] 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.best.top.validate.TopInterceptor.intercept(TopInterceptor.java:47)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)at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:50)at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:504)at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
說實話這個提示真有誤導人的嫌疑,剛開始還以為是名稱不對,估計一般人看到這個提示都這樣想。然後查看StreamResult的原始碼才發現是因為InputStream為null的緣故,汗一個。看下源碼:
Java代碼
- if (inputStream == null) {
- // Find the inputstream from the invocation variable stack
- inputStream = (InputStream) invocation.getStack().findValue(conditionalParse(inputName, invocation));
- }
-
- if (inputStream == null) {
- String msg = ("Can not find a java.io.InputStream with the name [" + inputName + "] in the invocation stack. " +
- "Check the <param name=\"inputName\"> tag specified for this action.");
- LOG.error(msg);
- throw new IllegalArgumentException(msg);
- }