Your program is NOT desktop/standalone, since it is a servlet running on a server. When you run it in Eclipse by right clicking and run as
-> run on server
, Eclipse actually opens a web page to display the results. Therefore, your program is now a Web application, and Eclipse (or the page it opens) is the client. The client is saving the information you sent, NOT your program. Got it?
The content-disposition
header is there only to suggest the file name of the download. The browser settings define if it will open a Save As Window or not. You cannot control that.
For example, in Google Chrome, in Setting
/Advanced Setting
/Downloads
, there is the option Ask where to save each file before downloading
. Only if this option is selected it will open the dialog you want. Otherwise it will save it in a default location (also defined in the browser settings). Similar options exist for all browsers.
Please also note that, depending on the content-type
header, the browser will try to display the content, and not download it. For example, the browser will try to display texts and html. But then you can force the download by setting the header to a non-displayable type:
response.setContentType("application/octet-stream");
In case you don't want to create a Web app: Since your program runs on a server, it simply sends the information and is done. It is the client program who decides what to do with it. In your present case the client is a browser (or Eclipse opening a browser page). Headers such as the content-disposition
header are aimed at browsers. If you are to create your own client (Swing client, Android app, iPhone app) which is NOT a browser, then the client will receive the information from the server and decide what to do with it (display it, or save it in any way), even ignoring the HTTP headers.