RE: Struts newbie - Advice on file downloading
Hi, Thanks to Richard, Mike and Dale for your help. I've now got this working. The XML is downloading fine in my development environment. I'll worry about other browsers and formats further downstream. I've used contentType "text/xml" and contentDisposition attachment;filename="myfile.xml" as suggested by Dale. Cheers, Steve -Original Message- From: Richard Sayre [mailto:richardsa...@gmail.com] Sent: 13 May 2009 12:41 To: Struts Users Mailing List Subject: Re: Struts newbie - Advice on file downloading Hi, I have the following defined: application/pdf fileStream filename="Report.pdf" 1024 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 fileStream param) //fileStream is an InputStream fileStream = new ByteArrayInputStream(bout.toByteArray()); return SUCCESS; } You will have to parameterize the XML to handle multiple file types: ${mimeType} 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 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 - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: Struts newbie - Advice on file downloading
Richard Sayre wrote: filename="Report.pdf" That is an invalid contentDisposition value. We've recently fixed the documentation so that hopefully people will stop making this mistake. If you want it displayed in the browser: inline;filename="Report.pdf" If you want the browser to save it: attachment;filename="Report.pdf" http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.5.1 -Dale - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: Struts newbie - Advice on file downloading
Hi Steve, I haven't implemented this in struts before; but have in the past built other java web-apps w/ the downloading of files... the save-as dialog box is browser dependent (as Richard mentioned) and if a user has mucked w/ their mime-type settings you may not be able to force the regular save-as dialog... (with the types you mentioned pdf, csv, etc this is very likely; also if you have to support different browsers this may work differently or even be set differently between them) If you are in control of your end-user's environment (say a corporate env.) then this may not be a big deal; however if you aren't and you really need the save-as dialog in a rigid fashion; then perhaps putting in an applet is the way to go [this would even allow you to default to a certain directory regardless of the browser settings [in a req i have worked on in the past that was very important to my client since they're users weren't good at remember what directory they save things in] the user would have some extra work to accept the signed/self-signed applet on their first visit; but subsequent visits would be smooth and relatively consistent Good luck! -Mike - Original Message > From: Richard Sayre > To: Struts Users Mailing List > Sent: Wednesday, May 13, 2009 7:41:01 AM > Subject: Re: Struts newbie - Advice on file downloading > > Hi, > > I have the following defined: > > > method="generateReport"> > > application/pdf > fileStream > filename="Report.pdf" > 1024 > > > 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 > name="inputName">fileStream param) > //fileStream is an InputStream > fileStream = new ByteArrayInputStream(bout.toByteArray()); > > return SUCCESS; > } > > You will have to parameterize the XML to handle multiple file types: > > ${mimeType} > > 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 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 - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: Struts newbie - Advice on file downloading
Hi, I have the following defined: application/pdf fileStream filename="Report.pdf" 1024 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 fileStream param) //fileStream is an InputStream fileStream = new ByteArrayInputStream(bout.toByteArray()); return SUCCESS; } You will have to parameterize the XML to handle multiple file types: ${mimeType} 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 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
Struts newbie - Advice on file downloading
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