I have a Servlet (called Download) which send down a xml file (based on some query string). My question is how can I specify the name of the file on users's desktop when people hit my servlet?
Right now, it saves into a file called 'Download'.
but browsers can ignore it, and so can users when they save it.
42
Rahul Bhattacharjee
Ranch Hand
Joined: Nov 29, 2005
Posts: 2300
posted
0
When you are sending a file which the browser can open , then browser wouldnot give you the option of saving the file ; rather this would try to open the file.(Like html , xml , and pdf [if acrobat reader is installed.]). In case you want to send an xml , it would be read by the browser rather then giving the use an option to save this file.
then browser wouldnot give you the option of saving the file
Only if the user wants it so. The first time the browser sees an unknown file format it will ask the user what to do with it. If the user specifies that files of that type should be saved to disk, then the browser will not try to open them.
Rahul Bhattacharjee
Ranch Hand
Joined: Nov 29, 2005
Posts: 2300
posted
0
When you are sending a file which the browser can open , then browser wouldnot give you the option of saving the file
When the browser can open a file (in other words the browser understands the format of the data.) then it opens the files directly ,rather giving the user the option to save it.
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35241
7
posted
0
When the browser can open a file (in other words the browser understands the format of the data.) then it opens the files directly
This is incorrect. Please re-read my previous post. Files downloaded as described above will not be opened -no matter which file type they are- unless they user specifically requested that at some point. Until she does, the file save dialog will be shown.
Rahul Bhattacharjee
Ranch Hand
Joined: Nov 29, 2005
Posts: 2300
posted
0
Thanks Ulf , I got it now. But we have to set the content-disposition header for this to happen.Is that so ?