<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Sending Binary Data Via Struts</title>
	<atom:link href="http://www.mooreds.com/wordpress/archives/18/feed" rel="self" type="application/rss+xml" />
	<link>http://www.mooreds.com/wordpress/archives/18</link>
	<description></description>
	<lastBuildDate>Tue, 07 Feb 2012 14:11:43 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Johnny Hastings</title>
		<link>http://www.mooreds.com/wordpress/archives/18/comment-page-1#comment-3269</link>
		<dc:creator>Johnny Hastings</dc:creator>
		<pubDate>Mon, 31 Jan 2011 20:10:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.mooreds.com/wordpress/?p=18#comment-3269</guid>
		<description>Ashok, yer awesome. That solved my problem after a ton of investigation!

&quot;In struts 2.0 you can return Action.NONE in execute method and dont specify anything in struts.xml action specification. Use the output stream as like in struts. &quot;</description>
		<content:encoded><![CDATA[<p>Ashok, yer awesome. That solved my problem after a ton of investigation!</p>
<p>&#8220;In struts 2.0 you can return Action.NONE in execute method and dont specify anything in struts.xml action specification. Use the output stream as like in struts. &#8220;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: moore</title>
		<link>http://www.mooreds.com/wordpress/archives/18/comment-page-1#comment-3065</link>
		<dc:creator>moore</dc:creator>
		<pubDate>Fri, 16 Apr 2010 15:53:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.mooreds.com/wordpress/?p=18#comment-3065</guid>
		<description>Hi Karthik,

This is going to be an issue with sending any file over HTTP, because you can&#039;t send both text (a message) and a file for display in a browser at the same time.

You could try sending a http redirect header along with the file, but I&#039;m not sure exactly how to do this.</description>
		<content:encoded><![CDATA[<p>Hi Karthik,</p>
<p>This is going to be an issue with sending any file over HTTP, because you can&#8217;t send both text (a message) and a file for display in a browser at the same time.</p>
<p>You could try sending a http redirect header along with the file, but I&#8217;m not sure exactly how to do this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: karthik</title>
		<link>http://www.mooreds.com/wordpress/archives/18/comment-page-1#comment-3063</link>
		<dc:creator>karthik</dc:creator>
		<pubDate>Fri, 16 Apr 2010 09:05:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.mooreds.com/wordpress/?p=18#comment-3063</guid>
		<description>Hi,

In struts 1, is there any way to show errors or messages after file output.

I need to export a file of ms-excel type and display a message using saveErrors(req,err) or saveMessages(req,msg) methods.

But after file export. i got a exception as,


SEVERE: Servlet.service() for servlet ActionServlet threw exception
java.lang.IllegalStateException: getOutputStream() has already been called for this response

and the page is not forwarding. even the data in the forms are not reset. (i called actionForm.reset() method.)

any clues.
thanks.</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>In struts 1, is there any way to show errors or messages after file output.</p>
<p>I need to export a file of ms-excel type and display a message using saveErrors(req,err) or saveMessages(req,msg) methods.</p>
<p>But after file export. i got a exception as,</p>
<p>SEVERE: Servlet.service() for servlet ActionServlet threw exception<br />
java.lang.IllegalStateException: getOutputStream() has already been called for this response</p>
<p>and the page is not forwarding. even the data in the forms are not reset. (i called actionForm.reset() method.)</p>
<p>any clues.<br />
thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevin Fleischer</title>
		<link>http://www.mooreds.com/wordpress/archives/18/comment-page-1#comment-2233</link>
		<dc:creator>Kevin Fleischer</dc:creator>
		<pubDate>Mon, 26 May 2008 22:08:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.mooreds.com/wordpress/?p=18#comment-2233</guid>
		<description>Thats it!!
&gt;&gt;return NONE;</description>
		<content:encoded><![CDATA[<p>Thats it!!<br />
&gt;&gt;return NONE;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ashok</title>
		<link>http://www.mooreds.com/wordpress/archives/18/comment-page-1#comment-2193</link>
		<dc:creator>Ashok</dc:creator>
		<pubDate>Wed, 16 Jan 2008 15:06:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.mooreds.com/wordpress/?p=18#comment-2193</guid>
		<description>In struts 2.0 you can return Action.NONE in execute method and dont specify anything in struts.xml action specification. Use the output stream as like in struts. :-)</description>
		<content:encoded><![CDATA[<p>In struts 2.0 you can return Action.NONE in execute method and dont specify anything in struts.xml action specification. Use the output stream as like in struts. <img src='http://www.mooreds.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Almond Saria</title>
		<link>http://www.mooreds.com/wordpress/archives/18/comment-page-1#comment-2192</link>
		<dc:creator>Almond Saria</dc:creator>
		<pubDate>Wed, 16 Jan 2008 03:45:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.mooreds.com/wordpress/?p=18#comment-2192</guid>
		<description>thank you Arivazhagan kannan!!! works great for me!</description>
		<content:encoded><![CDATA[<p>thank you Arivazhagan kannan!!! works great for me!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arivazhagan kannan</title>
		<link>http://www.mooreds.com/wordpress/archives/18/comment-page-1#comment-2137</link>
		<dc:creator>Arivazhagan kannan</dc:creator>
		<pubDate>Thu, 13 Sep 2007 10:14:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.mooreds.com/wordpress/?p=18#comment-2137</guid>
		<description>Use this code for sending binary data via STRUTS/Servlet/Jsp:

File pdfFile = new File(pdfFileName);
      response.setContentType(BIRTSchedulerConstants.CONTENT_TYPE);
      response.setContentLength((int) pdfFile.length());

      response.setHeader(&quot;Content-Disposition&quot;, &quot;attachment; filename=\&quot;&quot; + pdfFile.getName() + &quot;\&quot;&quot;);

      response.setHeader(BIRTSchedulerConstants.CACHE_CONTROL, BIRTSchedulerConstants.NO_CACHE);
      response.flushBuffer();
      OutputStream outStream = response.getOutputStream();
      byte[] buf = new byte[(int) pdfFile.length()];
      FileInputStream inStream = new FileInputStream(pdfFile);
      int sizeRead = 0;
      while ((sizeRead = inStream.read(buf, 0, buf.length)) &gt; 0) {
        outStream.write(buf, 0, sizeRead);
      }
      inStream.close();
      outStream.flush();

Note: In struts action, use the mapping.findforward(null). becoz flush() method will submit the data to response stream. so if u redirect to another page then u will get response.getOutputStream() been already called error.</description>
		<content:encoded><![CDATA[<p>Use this code for sending binary data via STRUTS/Servlet/Jsp:</p>
<p>File pdfFile = new File(pdfFileName);<br />
      response.setContentType(BIRTSchedulerConstants.CONTENT_TYPE);<br />
      response.setContentLength((int) pdfFile.length());</p>
<p>      response.setHeader(&#8220;Content-Disposition&#8221;, &#8220;attachment; filename=\&#8221;" + pdfFile.getName() + &#8220;\&#8221;");</p>
<p>      response.setHeader(BIRTSchedulerConstants.CACHE_CONTROL, BIRTSchedulerConstants.NO_CACHE);<br />
      response.flushBuffer();<br />
      OutputStream outStream = response.getOutputStream();<br />
      byte[] buf = new byte[(int) pdfFile.length()];<br />
      FileInputStream inStream = new FileInputStream(pdfFile);<br />
      int sizeRead = 0;<br />
      while ((sizeRead = inStream.read(buf, 0, buf.length)) &gt; 0) {<br />
        outStream.write(buf, 0, sizeRead);<br />
      }<br />
      inStream.close();<br />
      outStream.flush();</p>
<p>Note: In struts action, use the mapping.findforward(null). becoz flush() method will submit the data to response stream. so if u redirect to another page then u will get response.getOutputStream() been already called error.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sangeetha Sundaram</title>
		<link>http://www.mooreds.com/wordpress/archives/18/comment-page-1#comment-2034</link>
		<dc:creator>Sangeetha Sundaram</dc:creator>
		<pubDate>Mon, 05 Feb 2007 18:52:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.mooreds.com/wordpress/?p=18#comment-2034</guid>
		<description>Hi All,
I too had a similiar problem when I try to open a file using struts action. I was getting response is already in use.

I did the file reading and wrote it to the Outputstream and then retun null instead of any action. This solved my issue and everything is fine.

It is just that we open a ouput stream in the action and when we forward to any jsp, the container tries to open an output stream to write the JSP contents.</description>
		<content:encoded><![CDATA[<p>Hi All,<br />
I too had a similiar problem when I try to open a file using struts action. I was getting response is already in use.</p>
<p>I did the file reading and wrote it to the Outputstream and then retun null instead of any action. This solved my issue and everything is fine.</p>
<p>It is just that we open a ouput stream in the action and when we forward to any jsp, the container tries to open an output stream to write the JSP contents.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Patrik Thornblad</title>
		<link>http://www.mooreds.com/wordpress/archives/18/comment-page-1#comment-13</link>
		<dc:creator>Patrik Thornblad</dc:creator>
		<pubDate>Wed, 15 Feb 2006 16:08:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.mooreds.com/wordpress/?p=18#comment-13</guid>
		<description>I was actually wrong in my conclusion the useBean tag was resplonsible for the newline character. In fact, the JSP contained
a newline character between the opening and closing useBean tag. By removing this, it worked fine with the useBean tag!

Non-working jsp jsp:

&lt;%@ page
...
%&gt;&lt;jsp:useBean
  id=&quot;actionForm&quot;
  scope=&quot;request&quot;
  type=&quot;mypackage.MyActionForm&quot;&gt;
&lt;/jsp:useBean&gt;&lt;% /** Java code **/ %&gt;

Working jsp:

&lt;%@ page
...
%&gt;&lt;jsp:useBean
  id=&quot;actionForm&quot;
  scope=&quot;request&quot;
  type=&quot;mypackage.MyActionForm&quot;
&gt;&lt;/jsp:useBean&gt;&lt;% /** Java code **/ %&gt;

</description>
		<content:encoded><![CDATA[<p>I was actually wrong in my conclusion the useBean tag was resplonsible for the newline character. In fact, the JSP contained<br />
a newline character between the opening and closing useBean tag. By removing this, it worked fine with the useBean tag!</p>
<p>Non-working jsp jsp:</p>
<p>&lt;%@ page<br />
&#8230;<br />
%&gt;&lt;jsp:useBean<br />
  id=&#8221;actionForm&#8221;<br />
  scope=&#8221;request&#8221;<br />
  type=&#8221;mypackage.MyActionForm&#8221;&gt;<br />
&lt;/jsp:useBean&gt;&lt;% /** Java code **/ %&gt;</p>
<p>Working jsp:</p>
<p>&lt;%@ page<br />
&#8230;<br />
%&gt;&lt;jsp:useBean<br />
  id=&#8221;actionForm&#8221;<br />
  scope=&#8221;request&#8221;<br />
  type=&#8221;mypackage.MyActionForm&#8221;<br />
&gt;&lt;/jsp:useBean&gt;&lt;% /** Java code **/ %&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Patrik Thornblad</title>
		<link>http://www.mooreds.com/wordpress/archives/18/comment-page-1#comment-12</link>
		<dc:creator>Patrik Thornblad</dc:creator>
		<pubDate>Thu, 09 Feb 2006 15:41:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.mooreds.com/wordpress/?p=18#comment-12</guid>
		<description>I would like to add a comment to your article &quot;Sending Binary Data Via Struts&quot;. I&#039;m having the same problem as you have (had) with
generating binary content from JSP in Struts. We&#039;re using IBM WebSphere and are about to upgrade from WebSphere4 to WebSphere6.

Everything worked fine in WAS4, but not now in WAS6. The binary data is generated and displayed on screen, but it is followed by ugly
stack traces on the server console: &quot;OutputStream already obtained&quot;.

But by inspecting the stack trace, I realised that the exception was *not* thrown when my code &quot;response.getOutputstream&quot; was executed.
Instead, the exception was thrown after all the code in the JSP had finished executing, which explains why I first got the file and then
was followed by the ugly stack trace.

I also found the cause. WAS has a feature called &quot;keepgenerated&quot; which, if set to true, keeps the java code that is generated from the
JSP. By inspecting the generated java code I discovered that WAS6 causes a \r\n to be written to the implicit variable &quot;out&quot; (of type
JSPWriter):

&lt;jsp:useBean
  id=&quot;actionForm&quot;
  scope=&quot;request&quot;
  type=&quot;mypackage.MyActionForm&quot;&gt;
&lt;/jsp:useBean&gt;

The exception was thrown when WAS tried to flush &quot;out&quot; (containing the \r\n), *after* the binary data had been sent to the client.

It didn&#039;t help to write like this either:

&amp;lt%@ page
...
%&gt;&lt;jsp:useBean
  ...
&lt;/jsp:useBean&gt;&lt;% /** Java code **/ %&gt;

The solution was to replace the useBean tag with java code:

&lt;%@ page
...
%&gt;&lt;%

  mypackage.MyActionForm actionForm = null;
  actionForm = (mypackage.MyActionForm) request.getAttribute(&quot;actionForm&quot;);

/** Java code **/ %&gt;</description>
		<content:encoded><![CDATA[<p>I would like to add a comment to your article &#8220;Sending Binary Data Via Struts&#8221;. I&#8217;m having the same problem as you have (had) with<br />
generating binary content from JSP in Struts. We&#8217;re using IBM WebSphere and are about to upgrade from WebSphere4 to WebSphere6.</p>
<p>Everything worked fine in WAS4, but not now in WAS6. The binary data is generated and displayed on screen, but it is followed by ugly<br />
stack traces on the server console: &#8220;OutputStream already obtained&#8221;.</p>
<p>But by inspecting the stack trace, I realised that the exception was *not* thrown when my code &#8220;response.getOutputstream&#8221; was executed.<br />
Instead, the exception was thrown after all the code in the JSP had finished executing, which explains why I first got the file and then<br />
was followed by the ugly stack trace.</p>
<p>I also found the cause. WAS has a feature called &#8220;keepgenerated&#8221; which, if set to true, keeps the java code that is generated from the<br />
JSP. By inspecting the generated java code I discovered that WAS6 causes a \r\n to be written to the implicit variable &#8220;out&#8221; (of type<br />
JSPWriter):</p>
<p>&lt;jsp:useBean<br />
  id=&#8221;actionForm&#8221;<br />
  scope=&#8221;request&#8221;<br />
  type=&#8221;mypackage.MyActionForm&#8221;&gt;<br />
&lt;/jsp:useBean&gt;</p>
<p>The exception was thrown when WAS tried to flush &#8220;out&#8221; (containing the \r\n), *after* the binary data had been sent to the client.</p>
<p>It didn&#8217;t help to write like this either:</p>
<p>&amp;lt%@ page<br />
&#8230;<br />
%&gt;&lt;jsp:useBean<br />
  &#8230;<br />
&lt;/jsp:useBean&gt;&lt;% /** Java code **/ %&gt;</p>
<p>The solution was to replace the useBean tag with java code:</p>
<p>&lt;%@ page<br />
&#8230;<br />
%&gt;&lt;%</p>
<p>  mypackage.MyActionForm actionForm = null;<br />
  actionForm = (mypackage.MyActionForm) request.getAttribute(&#8220;actionForm&#8221;);</p>
<p>/** Java code **/ %&gt;</p>
]]></content:encoded>
	</item>
</channel>
</rss>
<!-- This Quick Cache file was built for (  www.mooreds.com/wordpress/archives/18/feed ) in 4.02783 seconds, on Feb 8th, 2012 at 9:04 pm UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 8th, 2012 at 10:04 pm UTC -->
