After looking in the *source code* of the Struts showcase, I got the idea to
declare an action with a return type of "stream" and use a method like

public InputStream retrieveImage() throws Exception {
 return ServletActionContext.getServletContext
().getResourceAsStream("images/403.jpg");
}

However, when I try this, an exception gets thrown:

java.lang.ClassCastException: java.io.ByteArrayInputStream
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(
DefaultActionInvocation.java:404)
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(
DefaultActionInvocation.java:262)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(
DefaultActionInvocation.java:224)
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(
DefaultWorkflowInterceptor.java:213)

(etc)

I'm really puzzled.  Simply returning an input stream of binary data from a
file or database object shouldn't be a big problem...should it?

-Brian



On 3/21/07, Brian Thompson <[EMAIL PROTECTED]> wrote:

I'm trying to return a stream of binary data (like the image or .zip
example on http://www.planetstruts.org/struts2-showcase/filedownload/index.jsp
) from a Struts 2 action class, but I'm not sure how to configure my
application to get Struts to write the data directly to the response without
trying to route it through a jsp.


http://www.planetstruts.org/struts2-showcase/viewSource.action?page=/filedownload/index.jspseems
 like it should do the trick, but it's missing the 2/3 of the
documentation that I need (the Action class source and the configuration).

Has anyone had any luck in getting this kind of behavior out of Struts 2?


-Brian

Reply via email to