Struts 拦截器给出流结果

发布于 2024-11-07 19:24:46 字数 1238 浏览 2 评论 0原文

我有一个拦截器,我试图在调用某个操作时输出流。这是我在拦截器中的代码的一部分:

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 中:

<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.

让它输出我想要的内容是否是一个失败的原因?我还没有发现有人做类似的事情。 此代码尝试解决我的其他问题

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 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>

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天涯沦落人 2024-11-14 19:24:46

Struts2 正在您的操作中查找 getInputStream() 方法,但没有找到。

您可以尝试从拦截器内手动将 inputStream 放入堆栈中。像这样的东西:

invocation.getInvocationContext().put("inputStream", inputStream);

Struts2 is looking for the getInputStream() method on your action and it isn't finding it.

You could try placing the inputStream on the stack manually from within the interceptor. Something like:

invocation.getInvocationContext().put("inputStream", inputStream);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文