Can anyone please tell me how to download files from a servlet? Im talking about those "pop-ups " like JFileChooser that allow you to specify the directory you want to download the file to. Thanks
"Human beings can alter their lives by altering their state of mind" William James
The first header indicates what kind of MIME type the file is you're streaming to the client, while the second specifies that the file should not be displayed by the browser, but instead should be stored as a file. You can change the suggested filename and use something more descriptive than "file.txt". [ January 27, 2006: Message edited by: Ulf Dittmer ]
the only thing that its not downloading my attached file, rather, its set the filename to null, and its downloading the dynamic html generated by my servlet into a file.
So am i supposed to actually code for the download itself?
please the part of the code that has getServletContext.getResourceAsStream("Web.inf",filename) is a bit confusing. What is web-inf doing there? is that where the resource is meant to be stored? im sorry if im asking a silly question, but ive never seen that before. thanks
This servlet is part of a demo app that streams image files from behind the WEB-INF directory.
The getResourceAsStream method takes as it's argument the path of the file that you want to work with, relative to the root of your webapp.
In this case, I'm prepending "/WEB-INF" to the user supplied file name.
See: java.lang.String)" target="_blank" rel="nofollow">http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletContext.html#getResourceAsStream(java.lang.String) for more information.
Adewale Adebusoye
Ranch Hand
Joined: Sep 28, 2005
Posts: 118
posted
0
please the part of the code that has getServletContext.getResourceAsStream("Web.inf",filename) is a bit confusing. What is web-inf doing there? is that where the resource is meant to be stored? im sorry if im asking a silly question, but ive never seen that before. thanks