You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Brian McGovern <bm...@imediainc.com> on 2005/04/26 19:47:00 UTC

PDF Streamed To Client

I'm wondering if anyone has any tips on how to render a pdf with struts.  I want to mask the name of the pdf and just stream it to client.

Thanks

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: PDF Streamed To Client

Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
Or use the new DownloadAction - it is in the Struts 1.2.6 beta version,
Details on the wiki

http://wiki.apache.org/struts/StrutsFileDownload

http://svn.apache.org/dist/struts/v1.2.6/

Niall

----- Original Message ----- 
From: "Nick Heudecker" <nh...@gmail.com>
Sent: Tuesday, April 26, 2005 6:46 PM


Brian:

This is pretty simple.  Just get the output stream from the response
object and stream the file down.  Return null from the Action's
execute method:

    private void returnFile(File f, OutputStream out) throws IOException {
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(f);
            byte[] buf = new byte[8 * 1024];
            int bytesRead;
            while ((bytesRead = fis.read(buf)) != -1) {
                out.write(buf, 0, bytesRead);
            }
        } catch (IOException ioe) {
            log.error(ioe, ioe);
        } finally {
            if (fis != null)
                fis.close();
        }
    }

On 4/26/05, Brian McGovern <bm...@imediainc.com> wrote:
> I'm wondering if anyone has any tips on how to render a pdf with struts.
I want to mask the name of the pdf and just stream it to client.
>
> Thanks

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org





---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: PDF Streamed To Client

Posted by Nick Heudecker <nh...@gmail.com>.
Brian:

This is pretty simple.  Just get the output stream from the response
object and stream the file down.  Return null from the Action's
execute method:

    private void returnFile(File f, OutputStream out) throws IOException {
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(f);
            byte[] buf = new byte[8 * 1024];
            int bytesRead;
            while ((bytesRead = fis.read(buf)) != -1) {
                out.write(buf, 0, bytesRead);
            }
        } catch (IOException ioe) {
            log.error(ioe, ioe);
        } finally {
            if (fis != null)
                fis.close();
        }
    }

On 4/26/05, Brian McGovern <bm...@imediainc.com> wrote:
> I'm wondering if anyone has any tips on how to render a pdf with struts.  I want to mask the name of the pdf and just stream it to client.
> 
> Thanks

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: PDF Streamed To Client

Posted by Je...@bcbstx.com.



I have successfully used the following technique for file download via an
action:

Set the mimetype in the web.xml

Do nothing action always returns 'success' points to tiles def for file to
be downloaded

action-map:
<action path="/fileDownloadAction"
        type="com.foo.action.SuccessAction"
        name="someInitiatingForm" validate="false" scope="request">
  <forward name="success" path="file.download.entry" />
</action>

tiles-def:
<definition name="file.download.entry" path="path/to/my/file/foo.pdf">
</definition>

-Jeff





I'm wondering if anyone has any tips on how to render a pdf with struts.  I
want to mask the name of the pdf and just stream it to client.

Thanks





**********
The information contained in this communication is confidential, private, proprietary, or otherwise privileged and is intended only for the use of the addressee.  Unauthorized use, disclosure, distribution or copying is strictly prohibited and may be unlawful.  If you have received this communication in error, please notify the sender immediately at (312)653-6000 in Illinois; (972)766-6900 in Texas; or (800)835-8699 in New Mexico.
**********


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org