在 Struts2 中使用流结果 [英] Using Stream Result with Struts2

查看:25
本文介绍了在 Struts2 中使用流结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用流结果从 struts2 应用程序返回图像.我似乎在配置操作时遇到问题.这是配置:

I am attempting to use a Stream Result to return an image from a struts2 application. I seem to be having problem with configuring the action. Here is the configuration:

    <result name="success" type="stream">
            <param name="contentType">image/jpeg</param>
            <param name="inputName">inputStream</param>
            <param name="contentDisposition">filename="${filename}"</param>
            <param name="bufferSize">1024</param>
    </result>

问题似乎是 inputName 参数,根据文档是:

The problem seem to be the inputName parameter which according to the docs is:

来自链式操作的 InputStream 属性的名称(默认值 = inputStream).

the name of the InputStream property from the chained action (default = inputStream).

我不确定我应该在那里放什么名字.我得到的错误是:

I am not sure what name I should put there. The error I get is:

在调用堆栈中找不到名为 [inputStream] 的 java.io.InputStream.

Can not find a java.io.InputStream with the name [inputStream] in the invocation stack.

有人用过这个吗?有什么建议吗?

Has anyone used this before? Any advice?

谢谢.

推荐答案

I found this 解释了 InputStream 必须由我创建.我从我希望用户下载的文件中创建一个 InputStream 然后将 Stream 传递给结果是有道理的.我想这就是我的答案.

I found this which explained that the InputStream has to be created by me. It makes sense that I create an InputStream from the file that I want the user to download and then pass the Stream to the result. I guess that's my answer.

这篇关于在 Struts2 中使用流结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆