Re: How do i specify the filename for a binary file generated by a JSP?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Jonathan, Jonathan Mast wrote: I am writing a report generator that has the ability to generate Excel files. This question has already been answered by Youssef, Hassan, and Bill. I'm going to add a few things that I think are worth mentioning. There was a magazine at one time called JavaPro that seems to have been wiped off the face of the planet. I have in front of me a printed article called Send Files to Browser Clients the /Right Way/ which answers your question in a 2-page writeup. The basics are: 1. Use Content-Disposition (as suggested by other responses) 2. Set the Content-Type to application/octet-stream (This may force a download for browsers such as MSIE that would rather show you the content than download it) 3. Make sure you don't send more content than is appropriate. Since you're using a JSP, watch out for excess newlines and stuff like that you might get with sloppy JSP syntax. Sweet. The Way Back Machine comes to the rescue: http://web.archive.org/web/20020604100834/http://www.fawcette.com/javapro/2002_03/online/online_eprods/servlets_03_08/ Enjoy. It's a really old article, but it is actually still correct (which just isn't true for most of what has been published about Java - aside from the basics - since it was introduced). - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkkkKEcACgkQ9CaO5/Lv0PAPbACffXS7jmqO5m5mX+a9xqrKzs51 8O4AniTQoEYFpvZQTGVyRChPIAHlZI+R =0i+q -END PGP SIGNATURE- - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
How do i specify the filename for a binary file generated by a JSP?
I am writing a report generator that has the ability to generate Excel files. The user clicks on a link (exporter.jsp), the page's content-type has been set to application/vnd.ms-excel which naturally prompts the user to either save to a file or open directly in Excel. It works fine, but requires the user to manually rename the generated file from exporter.jsp to whatever.xls. Furthermore, Firefox will not let you rename the file in save dialog box, it just automatically saves the file as exporter.jsp, you must rename it from the file browser. How do specify the output file name from within JSP? Btw, right clicking and selecting save link as allows for specifying the file name, but the file that is created is empty. Thanks
Re: How do i specify the filename for a binary file generated by a JSP?
doesn't seem like a tomcat issue. you'd better ask in java/jsp groups. As a quick hint might use servlet in front of the jsp and whatever name you wana. Regards, Youssef On Wed, Nov 19, 2008 at 3:25 AM, Jonathan Mast [EMAIL PROTECTED]wrote: I am writing a report generator that has the ability to generate Excel files. The user clicks on a link (exporter.jsp), the page's content-type has been set to application/vnd.ms-excel which naturally prompts the user to either save to a file or open directly in Excel. It works fine, but requires the user to manually rename the generated file from exporter.jsp to whatever.xls. Furthermore, Firefox will not let you rename the file in save dialog box, it just automatically saves the file as exporter.jsp, you must rename it from the file browser. How do specify the output file name from within JSP? Btw, right clicking and selecting save link as allows for specifying the file name, but the file that is created is empty. Thanks
Re: How do i specify the filename for a binary file generated by a JSP?
On Tue, Nov 18, 2008 at 5:25 PM, Jonathan Mast [EMAIL PROTECTED] wrote: How do specify the output file name from within JSP? Something like: response.setHeader(Content-disposition, attachment; filename= + encodedFileName); :: will prompt the user to `Save as` with the specified file name. HTH, -- Hassan Schroeder [EMAIL PROTECTED] - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How do i specify the filename for a binary file generated by a JSP?
You need to do something like: % response.setHeader(Content-Disposition, attachment; filename=+whatever.xls); % Jonathan Mast [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I am writing a report generator that has the ability to generate Excel files. The user clicks on a link (exporter.jsp), the page's content-type has been set to application/vnd.ms-excel which naturally prompts the user to either save to a file or open directly in Excel. It works fine, but requires the user to manually rename the generated file from exporter.jsp to whatever.xls. Furthermore, Firefox will not let you rename the file in save dialog box, it just automatically saves the file as exporter.jsp, you must rename it from the file browser. How do specify the output file name from within JSP? Btw, right clicking and selecting save link as allows for specifying the file name, but the file that is created is empty. Thanks - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]