我们都知道jsp的内置对象有一个out,它是通过PageContext.getOut()来获取的,而在j2ee的开发api文档中写有Calling flush() on the ServletOutputStream commits the response. Either this method or getWriter() may be called to write the body, not both.调用flush()方法会提交response流,getWriter()和getOutPutStream()两者只能被调用一个
原因
两个流使用的是同一个缓冲区,当缓冲区满后 才会被写出(或手动调用flush写出) 在编译后的jsp类中,有一句: if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context);} 释放时会调用response.getWriter()