response.setHeader("Content-Disposition", "attachment; filename=file.txt");
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 ]
Originally posted by Adewale Adebusoye:
i included the servlet response headers:
response.setHeader("Content-Disposition", "attachment; filename=file.txt"));
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?
Fortunately, this is not too difficult:
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.
for more information.