﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-为实现梦想而努力-文章分类-JAVA</title><link>http://www.blogjava.net/mlxlzc/category/31532.html</link><description /><language>zh-cn</language><lastBuildDate>Fri, 16 May 2008 12:28:12 GMT</lastBuildDate><pubDate>Fri, 16 May 2008 12:28:12 GMT</pubDate><ttl>60</ttl><item><title>getOutputStream() has already been called for this response问题的解决</title><link>http://www.blogjava.net/mlxlzc/articles/200822.html</link><dc:creator>goto</dc:creator><author>goto</author><pubDate>Fri, 16 May 2008 03:00:00 GMT</pubDate><guid>http://www.blogjava.net/mlxlzc/articles/200822.html</guid><wfw:comment>http://www.blogjava.net/mlxlzc/comments/200822.html</wfw:comment><comments>http://www.blogjava.net/mlxlzc/articles/200822.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/mlxlzc/comments/commentRss/200822.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/mlxlzc/services/trackbacks/200822.html</trackback:ping><description><![CDATA[getOutputStream() has already been called for this response问题的解决<br />
<br />
在jsp向页面输出图片的时候,使用response.getOutputStream()会有这样的提示：java.lang.IllegalStateException:getOutputStream() has already been called for this response,会抛出Exception<br />
原因一:<br />
&nbsp;JSP 默认的输出流为PrintWriter ,即&lt;% %&gt;以外的东西所默认的输出方式,如果你尝试在JSP中使用ServletOutputStream就会引起错误.要嘛直接改用Servlet输出 (复写service方法),要嘛删除除%&gt;&lt;%中的任何东西(包括HTML标签,空格,回车等东西)应该就可以。<br />
对于这样的情况应该这样来解决，删除%&gt;&lt;%之间的所有内容包括空格和换行符，最后也要消除空格和换行符，最好再加上一句response.reset()。<br />
原因二:<br />
&nbsp;&nbsp;&nbsp; &nbsp;<br />
在J2EE的API参考里有这么个:<br />
<br />
ServletResponse的getWriter()方法里会抛出这个异常,<br />
<br />
IllegalStateException - if the getOutputStream method has already been called<br />
for this response object<br />
<br />
而它的getOutputStream()方法里会抛出这个异常.<br />
<br />
IllegalStateException - if the getOutputStream method has already been called for this response object<br />
<br />
并且两者的函数申明里都有这么样的一句<br />
Either this method or getOutputStream() may be called to write the body, not both.<br />
Either this method or getWriter() may be called to write the body, not both.<br />
<br />
&nbsp;以上说明也解释了为什么在往页面中写入图片的时候要使用如下循环格式<br />
OutputStream output=response.getOutputStream();<br />
&nbsp;while((len=in.read(b)) &gt;0)<br />
&nbsp; {<br />
&nbsp; output.write(b,0,len); &nbsp;<br />
&nbsp; <br />
&nbsp; }<br />
&nbsp;output.flush();<br />
而不是把response.getOutputStream().write()放到循环体内
<img src ="http://www.blogjava.net/mlxlzc/aggbug/200822.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/mlxlzc/" target="_blank">goto</a> 2008-05-16 11:00 <a href="http://www.blogjava.net/mlxlzc/articles/200822.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>tomcat 无法调试当前J2EE工程问题 报souce not found</title><link>http://www.blogjava.net/mlxlzc/articles/200823.html</link><dc:creator>goto</dc:creator><author>goto</author><pubDate>Fri, 16 May 2008 03:00:00 GMT</pubDate><guid>http://www.blogjava.net/mlxlzc/articles/200823.html</guid><wfw:comment>http://www.blogjava.net/mlxlzc/comments/200823.html</wfw:comment><comments>http://www.blogjava.net/mlxlzc/articles/200823.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/mlxlzc/comments/commentRss/200823.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/mlxlzc/services/trackbacks/200823.html</trackback:ping><description><![CDATA[<p>在Eclipse 下调试Servlet 出现了Source not found for
XxxAction.execute（...）的问题，猜想是没有将Servlet代码加入到debug
路径下以致在调试的时候找不到Source，虽知道原因，却不知道怎么解决。<br />
只能在Eclipse 里乱逛，东点西击，最后终于发现了问题所在。<br />
进
入Window &gt; Preferences &gt; Tomcat &gt; Source Path，在Source Path
标签下有行文字：Add java projects to source path（Eclipse debugger will search
for source files in these projects）。将要调试的project 选中然后再调试，果然不再出现Source
not found for...了！！</p>
<p>还不行再从新部署一下 重启一下tomcat。就好</p>
<img src ="http://www.blogjava.net/mlxlzc/aggbug/200823.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/mlxlzc/" target="_blank">goto</a> 2008-05-16 11:00 <a href="http://www.blogjava.net/mlxlzc/articles/200823.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>