我正在寻找一种更简单的解决方案来在 Struts2 应用程序中的 JSP 页面内显示图像。到目前为止我找到的(并且正在工作)的解决方案是:Struts 2 dynamic image example .
但是,在我看来,将图像写为字节流似乎有点矫枉过正。还有其他更简单的解决方案吗?或者绝对有必要使用字节流?
简单地说,写<img src="#image_location_on_disk">
不是一个可接受的解决方案,因为我希望struts负责带来我的图像(在我的业务逻辑中我决定是否应该显示图像)
最佳答案
<小时/>If you want to stream the image for a location which is not publicly visible to the browser, then this is the standard way to do it.
<小时/>In that case just use
FileInputStream
to read image, assign it to the inputsream and use stream result for the action.
在 Struts2 中,您可以使用 stream
结果执行提供图像的任务,而不是直接写入响应。您还可以将此结果配置为相应的内容类型。
关于java - Struts 2显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30231804/