Can I force the browser to save a downloaded file with a name I specify, rather than the name of the URL?

Alexandros Kotsiras

Assuming that you want to save the file as "myFile.txt" you have to set the Content-Disposition response Header as follows :

response.setHeader("Content-Disposition", "attachment;filename=myFile.txt");

Note that even if the file is of a type that the browser can display ( .html .txt etc.) because you set the disposition type as "attachment", the browser will not open it but it will instead pop up a "save as" box.

See HTTP/1.1 specs at:

See also How do I download a (binary, text, executable) file from a servlet or JSP? (especially the feedback)