JSP上傳圖片產(chǎn)生 java.io.IOException: Stream closed異常解決方法_JSP教程
推薦:JSP程序員成長(zhǎng)之路一個(gè)普普通通的不正確是把 JSP當(dāng)作簡(jiǎn)化的Java,它不可能,(實(shí)際上, JSP是簡(jiǎn)化的Servlet)程序員一般試著沒(méi)有學(xué)習(xí)需要的支持技巧而直接學(xué)習(xí)JSP。JSP是一個(gè)銜接技術(shù),并且成功地連接您就得理解的還有的技術(shù)。可能您可以知道Java,HTML和java script,這代表著JSP用確實(shí)是
在做 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 后的代碼。如下(很很的醒目一下):
復(fù)制代碼 代碼如下:www.zhaotila.cn
...
}catch(Exception e){
e.printStackTrace();
}finally{
out.flush(); //
out.close();// 此處為源始代碼
DBHelper.freeConnection(connection);
}
out.write('\r'); // 如上我已經(jīng)關(guān)了 out 對(duì)象,但此處還在使用,所以便產(chǎn)生了如開(kāi)始所描述的異常
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ù)制代碼 代碼如下:www.zhaotila.cn
out.flush() ;
out = pageContext.pushBody(); // 關(guān)于該段程序的解釋,doc中已經(jīng)說(shuō)的很清楚。
如下:(要特別注意一下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ì)象
分享:java中IP地址轉(zhuǎn)換十進(jìn)制數(shù)實(shí)現(xiàn)代碼先看實(shí)例 代碼如下 class ip { private static long iptolong(string strip) //將127.0.0.1 形式的ip地址轉(zhuǎn)換成10進(jìn)制整數(shù),這里沒(méi)有進(jìn)行任何錯(cuò)誤處理 { int j=0; int i=0; long [] ip=new long[4]; int position1=strip.indexof(.); int position2=strip.indexof(.,po
相關(guān)JSP教程:
- jsp response.sendRedirect不跳轉(zhuǎn)的原因分析及解決
- JSP指令元素(page指令/include指令/taglib指令)復(fù)習(xí)整理
- JSP腳本元素和注釋復(fù)習(xí)總結(jié)示例
- JSP FusionCharts Free顯示圖表 具體實(shí)現(xiàn)
- 網(wǎng)頁(yè)模板:關(guān)于jsp頁(yè)面使用jstl的異常分析
- JSP頁(yè)面中文傳遞參數(shù)使用escape編碼
- 基于jsp:included的使用與jsp:param亂碼的解決方法
- Java Web項(xiàng)目中連接Access數(shù)據(jù)庫(kù)的配置方法
- JDBC連接Access數(shù)據(jù)庫(kù)的幾種方式介紹
- 網(wǎng)站圖片路徑的問(wèn)題:絕對(duì)路徑/虛擬路徑
- (jsp/html)網(wǎng)頁(yè)上嵌入播放器(常用播放器代碼整理)
- jsp下顯示中文文件名及絕對(duì)路徑下的圖片解決方法
JSP教程Rss訂閱編程教程搜索
JSP教程推薦
猜你也喜歡看這些
- 提升JSP頁(yè)面響應(yīng)速度的七大技巧
- JSP中可能會(huì)碰到的問(wèn)題解答
- J2ME游戲開(kāi)發(fā)技巧用setClip分割圖片
- jsp是什么文件 如何打開(kāi)jsp格式的文件
- 對(duì)JSP頁(yè)面?zhèn)髦抵形膩y碼的簡(jiǎn)單解決方法
- JSP實(shí)例程序統(tǒng)計(jì)當(dāng)前在線人數(shù)
- Windows下JSP開(kāi)發(fā)環(huán)境的配置
- jsp include引用非本級(jí)目錄網(wǎng)頁(yè)實(shí)現(xiàn)代碼
- 關(guān)于Jsp頁(yè)面的幾種傳參方式
- JSP初學(xué)者必須掌握的語(yǔ)法點(diǎn)
- 相關(guān)鏈接:
復(fù)制本頁(yè)鏈接| 搜索JSP上傳圖片產(chǎn)生 java.io.IOException: Stream closed異常解決方法
- 教程說(shuō)明:
JSP教程-JSP上傳圖片產(chǎn)生 java.io.IOException: Stream closed異常解決方法
。