我們都知道jsp的內(nèi)置對(duì)象有一個(gè)out,它是通過(guò)PageContext.getOut()來(lái)獲取的,而在j2ee的開(kāi)發(fā)api文檔中寫(xiě)有Calling flush() on the ServletOutputStream commits the response. Either this method or getWriter() may be called to write the body, not both.調(diào)用flush()方法會(huì)提交response流,getWriter()和getOutPutStream()兩者只能被調(diào)用一個(gè)
原因
兩個(gè)流使用的是同一個(gè)緩沖區(qū),當(dāng)緩沖區(qū)滿后 才會(huì)被寫(xiě)出(或手動(dòng)調(diào)用flush寫(xiě)出) 在編譯后的jsp類中,有一句: if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context);} 釋放時(shí)會(huì)調(diào)用response.getWriter()