I am looking for a simpler solution to display an image inside a JSP page, within a Struts2 application. The solution which I found so far (and is working) is this one: Struts 2 dynamic image example.
However, writing the image as a stream of bytes seems to me like an overkill. Is there any other simpler solution? or it is absolutely necessary to use a stream of bytes?
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
FileInputStreamto read image, assign it to the inputsream and use stream result for the action.
In Struts2 you can perform the task of serving image with the
stream result instead of writing directly to the response. You can also configure this result to the corresponding content type.