aspose file tools*
The moose likes Servlets and the fly likes How to fix the problem of need to click Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to fix the problem of need to click "Save" button TWICE on "File Download" popup?" Watch "How to fix the problem of need to click "Save" button TWICE on "File Download" popup?" New topic
Author

How to fix the problem of need to click "Save" button TWICE on "File Download" popup?

Kate Xu
Greenhorn

Joined: Jul 28, 2003
Posts: 11
I have a problem with implementing functionality that allow user to download a file. The file itself is created correctly and users can choose the "Save" option to save it on the hard disk to view it later. Those parts work fine.

The problem is that the user needs to click "Save" button TWICE on the "File Download" pop up window where you can choose "Would you like to open the file or save it to your computer?"

Here is the source code I use:

public void doPost(HttpServletRequest request, HttpServletResponse response)
{
try
{
String fileName="ABC.csv";
String line="test";

response.setContentType("text/plain");
PrintWriter writer = response.getWriter();

response.setHeader("Content-disposition",
"attachment; filename=" + fileName);

writer.println(line);

writer.flush();
writer.close();
}
catch (Throwable t)
{
t.printStackTrace();
}
finally {
//to do
}
}
Kate Xu
Greenhorn

Joined: Jul 28, 2003
Posts: 11
Let me add more details to this.. After the "File Download" IE popup is displayed, a user clicks "Save" button. Then instead of displaying the file brower, Internet Explorer will display "File Download" IE popup again. Then the user clicks "Save" button again, then file brower is displayed.

I am using IE 6.0.28.

A coworker got the same result on a different PC.

Any help is greatly appreciated.
Kerry Wilson
Ranch Hand

Joined: Oct 29, 2003
Posts: 254
THis should be fixed by changing this header:

Content-Type: application/x-msdownload

try that out.


http://www.goodercode.com
SCJP 1.4
Kate Xu
Greenhorn

Joined: Jul 28, 2003
Posts: 11
It works like a charm! Thank you very much!
 
 
subject: How to fix the problem of need to click "Save" button TWICE on "File Download" popup?