• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Kate Xu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
THis should be fixed by changing this header:

Content-Type: application/x-msdownload

try that out.
 
Kate Xu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works like a charm! Thank you very much!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic