Your program is not desktop / standalone, as 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 that opens) is a client . The client saves the information you sent, not your program. Got?
The content-disposition header is only for specifying the name of the file to download. Browser settings determine whether the Save As window opens or not. You cannot control it.
For example, in Google Chrome, in Setting / Advanced Setting / Downloads there is an Ask where to save each file before downloading option. Only if this option is selected, it will open the desired dialog box. Otherwise, it will save it in the default location (also defined in the browser settings). Similar options exist for all browsers.
Also note that depending on the content-type header, the browser will try to display the content, rather than loading 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");
If you do not want to create a web application: since your program runs on a server It simply sends information and is executed. This is a client program that decides what to do with it. In this case, the client is a browser (or Eclipse opens a browser page). Headers, such as the content-disposition header, are for browsers. If you want to create your client (Swing client, Android app, iPhone app) that is NOT a browser, then the client will receive information from the server and decide what to do with it (display it or save it in any way), even ignoring the headers HTTP
Marcg source share