I'm using IE 8. I have a
jsp page. At the bottom of the page is javascript code:
window.open('openFile.do?file=myfile.csv', '_blank', ...
which calls controller intended for opening file. It runs when jsp page loads.
My goal is that new window with 'save as' dialog should appear automatically. The controller looks like this
protected void findForward(DataActionContext actionContext) throws Exception {
super.findForward(actionContext);
HttpServletResponse response = actionContext.getHttpServletResponse();
HttpServletRequest request = actionContext.getHttpServletRequest();
String sFile = request.getParameter("file");
String sPath = ...
byte[] data = myFunctionReadingFile(new File(sPath + sFile));
ServletOutputStream outstream = response.getOutputStream();
response.setContentType("text/plain");
response.setContentLength(data.length);
response.setHeader("Content-disposition", "attachment; filename=" + sFile);
outstream.write(data);
It doesn't work properly. The window flickers and closes itself.
If I hold Ctrl, the window with dialog appears and stays, but pressing save or open closes it.
It works fine on one condition - the JS script must be run manually by clicking on button (onclick event). Then it works ok and file can be saved,
It seems to me, that it is some security reason in IE - button can do it, but loading page can't. What do you think ? Thanks.