隨筆-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
          主站蜘蛛池模板: 商洛市| 宜章县| 绥化市| 康乐县| 清徐县| 秀山| 红河县| 德兴市| 屏东县| 清涧县| 桂林市| 昂仁县| 沿河| 砀山县| 勐海县| 名山县| 晋州市| 博湖县| 右玉县| 蕲春县| 板桥市| 承德市| 集安市| 临汾市| 灵寿县| 普安县| 辰溪县| 颍上县| 兰溪市| 柳江县| 吉安县| 泌阳县| 沙河市| 乐至县| 普兰店市| 玛沁县| 射阳县| 西乌珠穆沁旗| 楚雄市| 甘孜| 新绛县|