隨筆-199  評論-203  文章-11  trackbacks-0
            我們在做文件上傳或者下載,或者過濾等操作時,可能要用到頁面的輸出流.

              例如在JSP使用:

          response.reset();
          response.setContentType(”application/vnd.ms-excel”);
          OutputStream s = response.getOutputStream();

              拋出異常:

          ERROR [Engine] StandardWrapperValve[jsp]: Servlet.service()
          for servlet jsp threw exception
          java.lang.IllegalStateException: getOutputStream()
          has already been called for this response

              從網上找了下資料,綜合一下原因分析:

              這是WEB容器生成的servlet代碼中有out.write(””),這個和JSP中調用的response.getOutputStream()產生沖突。即Servlet規范說明,不能既調用 response.getOutputStream(),又調用response.getWriter(),無論先調用哪一個,在調用第二個時候應會拋出 IllegalStateException,因為在jsp中,out變量是通過response.getWriter得到的,在程序中既用了response.getOutputStream,又用了out變量,故出現以上錯誤。

              解決方案:

              1.在程序中添加:
              out.clear();
              out = pageContext.pushBody();
              就可以了;

              2,不要在%][%之間寫內容包括空格和換行符

              3,在頁面寫入圖片的時候,需要

          flush()
           OutputStream utput=response.getOutputStream();
           output.flush();

              4,在頁面確定寫入

          posted on 2009-04-14 07:55 Werther 閱讀(1165) 評論(0)  編輯  收藏 所屬分類: 10.Java
          主站蜘蛛池模板: 闽清县| 平和县| 莲花县| 孟村| 抚宁县| 东乡县| 神农架林区| 金门县| 苍南县| 达孜县| 金湖县| 城步| 灌南县| 思南县| 孟村| 嘉义市| 高邮市| 汤原县| 怀宁县| 郴州市| 宣恩县| 沭阳县| 吉木乃县| 凭祥市| 汝城县| 庆元县| 达拉特旗| 历史| 碌曲县| 剑河县| 连城县| 棋牌| 陇川县| 苏尼特左旗| 安图县| 汨罗市| 泾阳县| 长宁区| 临泽县| 长子县| 政和县|