将流结果与 Struts2 一起使用
我正在尝试使用 Stream Result 从 struts2 应用程序返回图像。 我似乎在配置操作时遇到问题。 这是配置:
<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 参数,根据文档是:
链式操作的 InputStream 属性的名称(默认 = inputStream)。
我不确定我应该在那里起什么名字。 我得到的错误是:
在调用堆栈中找不到名为 [inputStream] 的 java.io.InputStream。
以前有人用过这个吗? 有什么建议吗?
谢谢。
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>
The problem seem to be the inputName parameter which according to the docs is:
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:
Can not find a java.io.InputStream with the name [inputStream] in the invocation stack.
Has anyone used this before? Any advice?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我相信您的 contentDisposition 错误,应该是:(
Chris)
I believe you have the contentDisposition wrong, it should be:
(Chris)
我发现这个解释说
InputStream
必须由我创建。 我从希望用户下载的文件创建一个InputStream
,然后将 Stream 传递给结果,这是有意义的。 我想这就是我的答案。I found this which explained that the
InputStream
has to be created by me. It makes sense that I create anInputStream
from the file that I want the user to download and then pass the Stream to the result. I guess that's my answer.inputname 定义输出“流”的方法名称
public InputStream getInputStream()
{
返回新的 ByteArrayInputStream ( _bytes );
}
Inputname defines the name of the method that outputs the "stream"
public InputStream getInputStream ()
{
return new ByteArrayInputStream ( _bytes );
}