JSP上傳圖片產(chǎn)生 java.io.IOException: Stream closed異常解決方法
更新時(shí)間:2012年12月31日 15:53:20 作者:
在做jsp上傳圖片時(shí),把java代碼直接改成 jsp,上傳時(shí)產(chǎn)生異常,很是疑惑,于是搜索整理了一下解決方法,需要了解的朋友可以參考下
在做 jsp 上傳圖片時(shí),把 java 代碼直接改成 jsp,上傳時(shí)產(chǎn)生 如下異常:
2012-12-31 8:59:21 org.apache.catalina.core.StandardWrapperValve invoke
嚴(yán)重: Servlet.service() for servlet jsp threw exception
java.io.IOException: Stream closed
...
百思不得其解,翻出 jsp 轉(zhuǎn)成 servlet 后的代碼。如下(很很的醒目一下):
...
}catch(Exception e){
e.printStackTrace();
}finally{
out.flush(); //
out.close();// 此處為源始代碼
DBHelper.freeConnection(connection);
}
out.write('\r'); // 如上我已經(jīng)關(guān)了 out 對(duì)象,但此處還在使用,所以便產(chǎn)生了如開始所描述的異常
out.write('\n');
} catch (Throwable t) {
if (!(t instanceof SkipPageException)){
out = _jspx_out;
if (out != null && out.getBufferSize() != 0)
try { out.clearBuffer(); } catch (java.io.IOException e) {}
if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
}
} finally {
_jspxFactory.releasePageContext(_jspx_page_context);
}
...
解決辦法:把程序中加紅加粗的代碼改成:
out.flush() ;
out = pageContext.pushBody(); // 關(guān)于該段程序的解釋,doc中已經(jīng)說的很清楚。
如下:(要特別注意一下flush()和clear()方法的區(qū)別,因?yàn)樾枨蟛煌绦蚴遣煌模?
PageContext 實(shí)現(xiàn)了抽象類 JspContext ,方法:pushBody(), 保存當(dāng)前的out對(duì)象
public abstract class BodyContent
extends JspWriter
out 內(nèi)置對(duì)象
2012-12-31 8:59:21 org.apache.catalina.core.StandardWrapperValve invoke
嚴(yán)重: Servlet.service() for servlet jsp threw exception
java.io.IOException: Stream closed
...
百思不得其解,翻出 jsp 轉(zhuǎn)成 servlet 后的代碼。如下(很很的醒目一下):
復(fù)制代碼 代碼如下:
...
}catch(Exception e){
e.printStackTrace();
}finally{
out.flush(); //
out.close();// 此處為源始代碼
DBHelper.freeConnection(connection);
}
out.write('\r'); // 如上我已經(jīng)關(guān)了 out 對(duì)象,但此處還在使用,所以便產(chǎn)生了如開始所描述的異常
out.write('\n');
} catch (Throwable t) {
if (!(t instanceof SkipPageException)){
out = _jspx_out;
if (out != null && out.getBufferSize() != 0)
try { out.clearBuffer(); } catch (java.io.IOException e) {}
if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
}
} finally {
_jspxFactory.releasePageContext(_jspx_page_context);
}
...
解決辦法:把程序中加紅加粗的代碼改成:
復(fù)制代碼 代碼如下:
out.flush() ;
out = pageContext.pushBody(); // 關(guān)于該段程序的解釋,doc中已經(jīng)說的很清楚。
如下:(要特別注意一下flush()和clear()方法的區(qū)別,因?yàn)樾枨蟛煌绦蚴遣煌模?
abstract void |
flush()Flush the stream. |
abstract void |
clear()Clear the contents of the buffer. |
PageContext 實(shí)現(xiàn)了抽象類 JspContext ,方法:pushBody(), 保存當(dāng)前的out對(duì)象
BodyContent |
pushBody()Return a new BodyContent object, save the current "out" JspWriter, and update the value of the "out" attribute in the page scope attribute namespace of the PageContext. |
public abstract class BodyContent
extends JspWriter
out 內(nèi)置對(duì)象
您可能感興趣的文章:
- 解決springboot報(bào)錯(cuò)Failed?to?parse?multipart?servlet?request;?nested?exception?is?java.io.IOException問題
- 什么情況下會(huì)出現(xiàn)java.io.IOException?:?Broken?pipe這個(gè)錯(cuò)誤以及解決辦法
- 解決Spring調(diào)用Feign報(bào)錯(cuò):java.io.IOException:Incomplete output stream問題
- java.io.IOException:?UT010029:?Stream?is?closed異常分析及解決
- Android創(chuàng)建文件時(shí)出現(xiàn)java.io.IOException:?Operation?not?permitted異常的解決方法
- java.io.IOException:你的主機(jī)中的軟件中止了一個(gè)已建立的連接踩坑實(shí)戰(zhàn)
- 解決Java中的java.io.IOException: Broken pipe問題
- AndroidApk混淆編譯時(shí),報(bào)告java.io.IOException...錯(cuò)誤解決辦法
- Caused by: java.io.IOException: DerInputStream.getLength(): lengthTag=111
相關(guān)文章
通過viewport實(shí)現(xiàn)jsp頁面支持手機(jī)縮放
這篇文章主要介紹了如何通過viewport實(shí)現(xiàn)jsp頁面支持手機(jī)縮放,需要的朋友可以參考下2014-05-05
使用JavaBean創(chuàng)建您的網(wǎng)上日歷本(2)
使用JavaBean創(chuàng)建您的網(wǎng)上日歷本(2)...
2006-10-10
jsp中頁面之間的跳轉(zhuǎn)forward與sendRedirect的區(qū)別
頁面之間的跳轉(zhuǎn)可以通過兩種方式實(shí)現(xiàn):forward和sendRedirect;forward:可以在JSP頁面中使用,可以在Servlet中實(shí)現(xiàn),需要的朋友可以了解下
2012-12-12
json實(shí)現(xiàn)jsp分頁實(shí)例介紹(附效果圖)
json的既簡單易懂,又傳輸迅速。并且能和javascript很好的融為一體;在不需要添加jar的前提下,能夠很好完成jsp分頁問題,接下來為大家介紹下如何實(shí)現(xiàn)
2013-04-04
EJB 3.0 開發(fā)指南之定時(shí)服務(wù)
EJB 3.0 開發(fā)指南之定時(shí)服務(wù)...
2006-10-10 
