struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andre Van Klaveren <>
Subject Re: PDF Streamed To Client
Date Tue, 26 Apr 2005 20:50:38 GMT

While Nick's solution certainly works, it doesn't follow best
practices, MVC in particular (No offense Nick).  Technically a view
component such as a Servlet or JSP should be responsible for writing
the response back to the client.  The Action is responsible for flow
control and interacting with business components.

I solved a similar problem by having the Action place a byte array of
the PDF content and the content type (as a String) in request scope
and forwarding to a Servlet.  The Servlet's (called
BinaryOutputServlet) sole purpose is to retrieve the content and
content type from request scope and stream it back to the client. 
This is where Nick's example code would fit nicely.

Now, in your case you would probably put a reference to the PDF file
in request scope instead of a byte array, especially if the PDF
documents are large.  In my case the content was relatively small and
was generated dynamically.

If you design the Servlet generically it can be reused in any project
that requires the application to stream the content of any type of
file to the client (gif, jpg, rdf, etc).

Andre Van Klaveren

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message