struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Richard Sayre <richardsa...@gmail.com>
Subject Re: Struts newbie - Advice on file downloading
Date Wed, 13 May 2009 11:41:01 GMT
Hi,

I have the following defined:

 <action name="generatePdf" class="com.abc.ReportAction"
method="generateReport">
            <result name="success" type="stream">
                <param name="contentType">application/pdf</param>
                <param name="inputName">fileStream</param>
                <param name="contentDisposition">filename="Report.pdf"</param>
                <param name="bufferSize">1024</param>
</result>

My action lookks like this

public String generateReport() {

//use api to build PDF
//the api takes an output stream
//so at the end of my method i have an output stream containg the file...

//bout is my output stream
//file stream is a member of my Action (referenced in the  <param
name="inputName">fileStream</param> param)
//fileStream is an InputStream
 fileStream = new ByteArrayInputStream(bout.toByteArray());

return SUCCESS;
}

You will have to parameterize the XML to handle multiple file types:

 <param name="contentType">${mimeType}</param>

Which you will set in your action.  Same goes for the other parameters.

I'm not sure how to get the browser to display a save dialog, I think
it has to do with the mime type.  I think application/octet-stream
will work.

-Rich

On Wed, May 13, 2009 at 8:55 AM, Steve <steve@sjlt.co.uk> wrote:
> Hi,
>
>
>
> I'm a Struts 2 newbie and I need to write some code to download dynamically
> created files in various formats (csv, txt and xml). I want the user to be
> presented with a "Save As" dialog regardless of file type.
>
>
>
> Does anyone have any advice / URL's for example code? I have found the
> "Result Stream" documentation on the Struts site and various code snippets.
> But I can't find any good complete examples.
>
>
>
> Many Thanks,
>
>
>
> Steve
>
> Steve Higham
>
>
>
>
>
>

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


Mime
View raw message