国产18禁黄网站免费观看,99爱在线精品免费观看,粉嫩metart人体欣赏,99久久99精品久久久久久,6080亚洲人久久精品

java認(rèn)證:簡(jiǎn)單理解Java中的輸出流異常

時(shí)間:2009-04-14 12:06:00   來(lái)源:無(wú)憂考網(wǎng)     [字體: ]
我們?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è)面確定寫入