Struts拦截器提供流结果 [英] Struts interceptor giving a stream result
问题描述
我有一个拦截器,我试图在某个动作调用时输出流.这是我在感知器中的代码的一部分:
I got an interceptor that I'm trying to get to output a stream when a certain action is calling. This is part of my code in the 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
拥有自己的getter和setter方法.
在struts.xml
中:
inputStream
has got it's own getters and setters.
And in struts.xml
:
<global-results>
<result type="stream" name="resultToGiveStream">
<param name="contentType">text/plain</param>
<param name="inputName">inputStream</param>
</result>
</global-results>
但是当我调用actionToTest时,我只能在控制台中收到它:
But when I call actionToTest I only receive this in my console:
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.
让它输出我想要的东西是一个迷茫的原因吗?我还没有发现任何人在做类似的事情. 此代码可避免其他问题
Is it a lost cause to get it to output what I want? I haven' found anyone doing anything similar. This code is an atempt for a workaround for my other question.
推荐答案
Struts2正在为您的操作寻找getInputStream()
方法,但没有找到它.
Struts2 is looking for the getInputStream()
method on your action and it isn't finding it.
您可以尝试从拦截器内部将inputStream手动放置在堆栈上.像这样:
You could try placing the inputStream on the stack manually from within the interceptor. Something like:
invocation.getInvocationContext().put("inputStream", inputStream);
这篇关于Struts拦截器提供流结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!