I’m generating an Excel document via Servlet. When I send the response back to the client (IE8), the “Open/Save” dialog pops up but requires users to click a choice twice before taking action. This doesn’t happen in Firefox. I have no idea why this is occurring. Below is the relevant code that creates the appropriate streams.
result contains the Excel XML.
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;filename=TestFile.xls");
InputStream in = new ByteArrayInputStream(result.toString().getBytes("UTF-8"));
ServletOutputStream out = response.getOutputStream();
try
{
byte[] outputByte = new byte[4096];
while(in.read(outputByte, 0, 4096) != -1)
out.write(outputByte, 0, 4096);
}
finally
{
in.close();
out.flush();
out.close();
}
EDIT
I have noticed that waiting 5+ seconds before clicking an option works just fine. It seems to only ask twice when immediately clicking an option.
This code works well for every type of file in my application
try it and let us know