我們?cè)谧鑫募蟼骰蛘呦螺d,或者過(guò)濾等操作時(shí),可能要用到頁(yè)面的輸出流.
例如在JSP使用:
response.reset();response.setContentType(”application/vnd.ms-excel”);OutputStream s = response.getOutputStream();
拋出異常:
ERROR [Engine] StandardWrapperValve[jsp]: Servlet.service()
for servlet jsp threw exceptionjava.lang.IllegalStateException: getOutputStream()
has already been called for this response
從網(wǎng)上找了下資料,綜合一下原因分析:
這是WEB容器生成的servlet代碼中有out.write(””),這個(gè)和JSP中調(diào)用的response.getOutputStream()產(chǎn)生沖突。即Servlet規(guī)范說(shuō)明,不能既調(diào)用 response.getOutputStream(),又調(diào)用response.getWriter(),無(wú)論先調(diào)用哪一個(gè),在調(diào)用第二個(gè)時(shí)候應(yīng)會(huì)拋出 IllegalStateException,因?yàn)樵趈sp中,out變量是通過(guò)response.getWriter得到的,在程序中既用了 response.getOutputStream,又用了out變量,故出現(xiàn)以上錯(cuò)誤。
解決方案:
1.在程序中添加:
out.clear();
out = pageContext.pushBody();
就可以了;
2,不要在%][%之間寫內(nèi)容包括空格和換行符
3,在頁(yè)面寫入圖片的時(shí)候,需要
flush() OutputStream utput=response.getOutputStream(); output.flush();
4,在頁(yè)面確定寫入
例如在JSP使用:
response.reset();response.setContentType(”application/vnd.ms-excel”);OutputStream s = response.getOutputStream();
拋出異常:
ERROR [Engine] StandardWrapperValve[jsp]: Servlet.service()
for servlet jsp threw exceptionjava.lang.IllegalStateException: getOutputStream()
has already been called for this response
從網(wǎng)上找了下資料,綜合一下原因分析:
這是WEB容器生成的servlet代碼中有out.write(””),這個(gè)和JSP中調(diào)用的response.getOutputStream()產(chǎn)生沖突。即Servlet規(guī)范說(shuō)明,不能既調(diào)用 response.getOutputStream(),又調(diào)用response.getWriter(),無(wú)論先調(diào)用哪一個(gè),在調(diào)用第二個(gè)時(shí)候應(yīng)會(huì)拋出 IllegalStateException,因?yàn)樵趈sp中,out變量是通過(guò)response.getWriter得到的,在程序中既用了 response.getOutputStream,又用了out變量,故出現(xiàn)以上錯(cuò)誤。
解決方案:
1.在程序中添加:
out.clear();
out = pageContext.pushBody();
就可以了;
2,不要在%][%之間寫內(nèi)容包括空格和換行符
3,在頁(yè)面寫入圖片的時(shí)候,需要
flush() OutputStream utput=response.getOutputStream(); output.flush();
4,在頁(yè)面確定寫入