有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Struts 2显示图像

我正在寻找一个更简单的解决方案,在一个JSP页面中,在一个Struts2应用程序中显示一个图像。到目前为止,我找到的解决方案是:Struts 2 dynamic image example

然而,在我看来,以字节流的形式编写图像似乎是一种过激的行为。还有其他更简单的解决方案吗?还是绝对有必要使用字节流

简单地说,编写<img src="#image_location_on_disk">不是一个可接受的解决方案,因为我希望struts负责提供我的映像(在我的业务逻辑中,我决定是否应该显示映像)


共 (1) 个答案

  1. # 1 楼答案

    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结果提供图像的任务,而不是直接写入响应。还可以将此结果配置为相应的内容类型