java - Struts 2显示图像

标签 java image jsp struts2

我正在寻找一种更简单的解决方案来在 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/

相关文章:

c++ - 如何从 C++ 中的 Base64 编码字符串在 GDI+ 中创建图像?

jquery - 将 arraylist 中的值返回到 ajax 成功函数

java - IntelliJ 调试 : Suspend whole VM then step on single thread

如果数据已经可用,则不会触发 Java 选择器 OP_READ

r - 在 R 中使用 cowplot 对齐 image() 图

ImageMagick 不转换 PNG 位深度

java - 首先将 ListView 项目添加到列表底部

java - 如何根据容器的宽度动态设置组件扩展属性

java - 在 Web 应用程序的后端使用 Java,在中间件中使用 PHP

java - Hibernate和数据库连接问题(JSP页面上没有显示数据)