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 <st...@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-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to