我有一个拦截器,我试图在某个动作调用时输出一个流。这是我在inteceptor中的代码的一部分:
InputStream inputStream;
public String intercept(ActionInvocation invocation) throws Exception
{
if (currAction.contentEquals("actionToTest"))
{
String result = "TRUE";
inputStream = new ByteArrayInputStream(result.getBytes("UTF-8"));
return "resultToGiveStream";
}
}
inputStream
已经拥有了它自己的吸气剂和制定者
在struts.xml
:
<global-results>
<result type="stream" name="resultToGiveStream">
<param name="contentType">text/plain</param>
<param name="inputName">inputStream</param>
</result>
</global-results>
但是当我调用actionToTest时,我只在控制台中收到它:
2011-maj-18 11:19:16 com.opensymphony.xwork2.util.logging.commons.CommonsLogger error
ALLVARLIG: 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.
让它输出我想要的东西是否是一个失败的原因?我没有发现有人在做类似的事情。 此代码是my other question的解决方法的尝试。
答案 0 :(得分:4)
Struts2正在为您的操作寻找getInputStream()
方法,但却找不到它。
您可以尝试从拦截器中手动将inputStream放在堆栈上。类似的东西:
invocation.getInvocationContext().put("inputStream", inputStream);