Thanx a lot. After I insert "return null" the exception about > 16:52:20,832 ERROR [UIBean] error when rendering > java.lang.IllegalStateException: getOutputStream() has already been called > > for this response
stopped. But I've still got the problem with IE6 - instead of file name I have the name of my action - as I understand IE6 takes the last part of my url because it looks like filename (dot) extension (FileContent.action?fileId=5067). And it is strange because it happens only when I use https and IE6. When it is http and IE6 it seems to be fine. Could anyone help with this stuff? Thank you very much! Sincerely yours. -----Original Message----- From: news [mailto:[EMAIL PROTECTED] On Behalf Of Laurie Harper Sent: Tuesday, April 22, 2008 9:23 PM To: user@struts.apache.org Subject: Re: Two problems: Struts2 + https + file load and Struts2 + file load + java.lang.IllegalStateException: getOutputStream() Filippov, Andrey wrote: > Hello everybody! > > I am trying to load file from DB. I use https. In Mozilla I get only one > exception but everything finally works. Here is my code and stack trace: > > public String execute() throws Exception { > super.execute(); > > byte[] file = null; > PolicyFileVO policyFile = > polInfoInstance.getPolicyFileById(fileId); > file = policyFile.getFile(); > String fileType = > polInfoInstance.getFileTypeById(policyFile.getType()) > .getContentType(); > if (file != null) { > this.response.setCharacterEncoding("utf-8"); > > > String fileName = policyFile.getFile_name(); > > > if (!fileType.startsWith("image")) { > this.response.addHeader("Content-Disposition", > "attachment; filename=" + fileName); > } > // final ServletContext sc = > ServletActionContext.getServletContext(); > this.response.setContentType(fileType); > this.response.setContentLength(file.length); > OutputStream o = null; > try { > o = response.getOutputStream(); > o.write(file); > o.flush(); > } catch (java.lang.IllegalStateException ex) { > log.error("IllegalStateException in > FileContent.execute() method " + ex); > }catch (java.io.IOException ex) { > log.error("IOException in FileContent.execute() > method " + ex); > }catch (java.lang.Exception ex) { > log.error("Exception in FileContent.execute() method > " + ex); > }finally{ > if (o != null){ > response.flushBuffer(); > o.close(); > } > } > } There's no return statement in there, which shouldn't even compile... > 16:52:20,832 ERROR [UIBean] error when rendering > java.lang.IllegalStateException: getOutputStream() has already been called > for this response > at org.apache.catalina.connector.Response.getWriter(Response.java:604) > ............................................................................................ > 16:52:21,004 ERROR [[default]] Servlet.service() for servlet default threw > exception > java.io.IOException: Error including path '/layouts/four_rows_layout.jsp'. > java.lang.IllegalStateException: getOutputStream() has already been called > for this response > at > org.apache.tiles.servlet.context.ServletTilesRequestContext.include(ServletTilesRequestContext.java:214) > at > org.apache.tiles.servlet.context.ServletTilesRequestContext.dispatch(ServletTilesRequestContext.java:183) > at > org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:417) > at > org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:368) This suggests Struts is trying to forward to a JSP after your action completes, which won't work since you've already sent a file back to the browser. You execute() method should be returning 'null' to tell Struts not to do this. > And the second part of my problem happens only in IE6 - when dialog of > opening/saving file instead of normal file name like myTest.pdf reflect the > action name - something like this: FileContent_action?fileId=5046 (only when > I use https - in http it looks fine - myTest.pdf). The file name to save to is specified by the Content-Disposition header, which you are not setting consistently. Sending a correct header every time should fix this problem. L. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]