在寫JSP程序的時(shí)候,如果程序中調(diào)用了response.getOutputStream()去向客戶端輸出文件等數(shù)據(jù)流,容器就會(huì)拋出這樣的異常:
Java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:596)
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:186)
產(chǎn)生這樣的異常原因:是web容器生成的servlet代碼中有out.write(""),這個(gè)和JSP中調(diào)用的response.getOutputStream()產(chǎn)生沖突.即Servlet規(guī)范說明,不能既調(diào)用response.getOutputStream(),又調(diào)用response.getWriter(),無論先調(diào)用哪一個(gè),在調(diào)用第二個(gè)時(shí)候應(yīng)會(huì)拋出IllegalStateException,因?yàn)樵趈sp中,out變量實(shí)際上是通過response.getWriter得到的,你的程序中既用了response.getOutputStream,又用了out變量,故出現(xiàn)以上錯(cuò)誤。
解決方案:在程序的最后添加:
out.clear();
out = pageContext.pushBody();
就可以了。
http://blog.erp100.com/html/39/3639-1547.html
Java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:596)
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:186)
產(chǎn)生這樣的異常原因:是web容器生成的servlet代碼中有out.write(""),這個(gè)和JSP中調(diào)用的response.getOutputStream()產(chǎn)生沖突.即Servlet規(guī)范說明,不能既調(diào)用response.getOutputStream(),又調(diào)用response.getWriter(),無論先調(diào)用哪一個(gè),在調(diào)用第二個(gè)時(shí)候應(yīng)會(huì)拋出IllegalStateException,因?yàn)樵趈sp中,out變量實(shí)際上是通過response.getWriter得到的,你的程序中既用了response.getOutputStream,又用了out變量,故出現(xiàn)以上錯(cuò)誤。
解決方案:在程序的最后添加:
out.clear();
out = pageContext.pushBody();
就可以了。
http://blog.erp100.com/html/39/3639-1547.html