Using Stream result with Struts2

I am trying to use Stream Result to return an image from a struts2 application. I seem to have problems setting up 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 is the inputName parameter, which according to the docs:

the name of the InputStream property from the associated action (default = inputStream).

I'm not sure which name I should put there. The error I am getting is:

Cannot find java.io.InputStream named [inputStream] in the call stack.

Has anyone used this before? Any tips?

Thanks.

+3
source share
3 answers

I found this which explains that an InputStream must be created by me. It makes sense that I create an InputStream from the file that I want to load to the user, and then pass the Stream to the result. I think my answer.

+5
source

I believe that you have the wrong content. It should be:

 <param name="contentDisposition">attachment; filename="${filename}"</param> 

(Chris)

+6
source

The login name defines the name of the method that displays the "stream"

public InputStream getInputStream () {return new ByteArrayInputStream (_bytes); }

+3
source

Source: https://habr.com/ru/post/1396621/


All Articles