Using Stream Result with Struts2

I am attempting to use a Stream Result to return an image from a struts2 application. I seem to be having problem with configuring 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 seem to be the inputName parameter which according to the docs is:

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

I am not sure what name I should put there. The error I get is:

Can not find a java.io.InputStream with the name [inputStream] in the invocation stack.

Has anyone used this before? Any advice?

Thanks.


Asked by: Arthur524 | Posted: 21-01-2022






Answer 1

I believe you have the contentDisposition wrong, it should be:

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

(Chris)

Answered by: Andrew103 | Posted: 22-02-2022



Answer 2

I found this which explained that the InputStream has to be created by me. It makes sense that I create an InputStream from the file that I want the user to download and then pass the Stream to the result. I guess that's my answer.

Answered by: Connie439 | Posted: 22-02-2022



Answer 3

Inputname defines the name of the method that outputs the "stream"

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

Answered by: Alina471 | Posted: 22-02-2022



Similar questions

javascript - Java method never called while using JSON RPC in Struts2

I'm trying to get some code working that a previous developer has written. Yep, he now left the company. :-( I have a JSON RPC call being made from the JS code. The JS all runs fine and the callback method gets an object back (not an error object). But the method on the Java class never gets hit. The smd method does get hit though. public String smd() { return SUCCESS; // break poin...


java - Is there any init method given for struts2 action class?

Is there any init method provided for struts 2 action class that can be called before every method of that action class? For example, I have an action class for struts 2 as given below import com.opensymphony.xwork2.ActionSupport; public class EmployeeAction extends ActionSupport{ private DepartmentDaoService deptService = new DepartmentDaoService() ; private EmployeeDaoService empServic...


java - how to return excel in Struts2 result?

I am trying to return an Excel sheet from my struts2 action class. I am not sure what result-type should I be using? Has anyone tried to return an excel from struts2 action class? I would like the user to be presented with open/save/cancel dialog box


java - Two struts2 webapps fail to start together

I have problems getting two different struts2 webapps to start together in tomcat. But each of the webapps start correctly when placed independently inside webapps folder of tomcat. I get the following in catalina.out logs- SEVERE: Error filterStart Aug 13, 2009 3:17:45 PM org.apache.catalina.core.StandardContext start SEVERE: Context [/admin] startup failed due to previous errors Environment- Java1...


java - Struts2 doesn't find jsp files

I've been trying to no avail to set up a simple Struts2 application so I can get on with learning the framework. Basically, what I am expecting to happen is that when an action is triggered that isn't defined, then a default page will be displayed. This app is being developed in Eclipse. I have a very simple struts.xml file set up in the WEB-INF/classes directory: &lt;struts&gt; &lt;!-- Incl...


java - Struts2 + jQuery - Sending regular updates to the client

I am implementing a functionality in my web app such that a client can generate the report by entering some data and clicking on the submit button. The problem is that report generation takes lot of time and the report might not generate if the user entered data is wrong. The complete report generation task has many sub-tasks and I want when the client presses submit then just below that page I want to show...


java - Spring & Struts2 REST - junit tests

I have three hierarchical layers injected in Spring - rest, business logic and database operations. Junit tests for BL and DAO are working OK, when rest can inject only business logic ioc layer. My supper class for junit tests: import org.springframework.test.AbstractTransactionalSpringContextTests; public class AbstractTest extends AbstractTransactionalSpringContextTests { protected static final S...


java - Adding global error on any field error in struts2

I am using Struts2 and a bunch of Validation with Annotations. How do I add a global error message as well on top of field validation errors. Thanks, Fedor


java - In Struts2, how do you share your common html across all pages?

In Struts2, how do you share your common html across all pages? In Asp.net, you've got Master pages, and in Rails there are Layouts. The idea is that your common html (eg the header, menu, and styles) are all easy to maintain because they are in one place, but for the life of me i can't find the equivalent feature in Struts2. Is it called something else, or something, is that why i can't find it?


java - Struts2 URL with .action

I want the URL of the below format http://localhost/users/abc rather than http://localhost/users?name=abc How to achieve this in Struts2?






Still can't find your answer? Check out these amazing Java communities for help...



Java Reddit Community | Java Help Reddit Community | Dev.to Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)



top