Return-Path: Delivered-To: apmail-struts-user-archive@www.apache.org Received: (qmail 24592 invoked from network); 22 Apr 2008 17:25:49 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 22 Apr 2008 17:25:49 -0000 Received: (qmail 24390 invoked by uid 500); 22 Apr 2008 17:25:38 -0000 Delivered-To: apmail-struts-user-archive@struts.apache.org Received: (qmail 24372 invoked by uid 500); 22 Apr 2008 17:25:38 -0000 Mailing-List: contact user-help@struts.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Struts Users Mailing List" Reply-To: "Struts Users Mailing List" Delivered-To: mailing list user@struts.apache.org Received: (qmail 23910 invoked by uid 99); 22 Apr 2008 17:25:37 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 Apr 2008 10:25:37 -0700 X-ASF-Spam-Status: No, hits=-1.0 required=10.0 tests=RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of jak-struts-user@m.gmane.org designates 80.91.229.2 as permitted sender) Received: from [80.91.229.2] (HELO ciao.gmane.org) (80.91.229.2) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 Apr 2008 17:24:44 +0000 Received: from root by ciao.gmane.org with local (Exim 4.43) id 1JoMEo-0003Vq-CH for user@struts.apache.org; Tue, 22 Apr 2008 17:25:02 +0000 Received: from cpe0016b5ef7ea1-cm0014e88ef4b4.cpe.net.cable.rogers.com ([99.233.20.4]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 22 Apr 2008 17:25:02 +0000 Received: from laurie by cpe0016b5ef7ea1-cm0014e88ef4b4.cpe.net.cable.rogers.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 22 Apr 2008 17:25:02 +0000 X-Injected-Via-Gmane: http://gmane.org/ To: user@struts.apache.org From: Laurie Harper Subject: Re: Two problems: Struts2 + https + file load and Struts2 + file load + java.lang.IllegalStateException: getOutputStream() Date: Tue, 22 Apr 2008 13:23:05 -0400 Lines: 71 Message-ID: References: <152A7ADA28EF554A81FCA1B814CE8EC34C047B272F@spbsrv-mail.t-systems.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: cpe0016b5ef7ea1-cm0014e88ef4b4.cpe.net.cable.rogers.com User-Agent: Thunderbird 2.0.0.12 (Macintosh/20080213) In-Reply-To: <152A7ADA28EF554A81FCA1B814CE8EC34C047B272F@spbsrv-mail.t-systems.ru> Sender: news X-Virus-Checked: Checked by ClamAV on apache.org 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: user-unsubscribe@struts.apache.org For additional commands, e-mail: user-help@struts.apache.org