隨筆-8  評論-8  文章-10  trackbacks-0
          //加入這2句
          out.clear();
          out=pageContext.pushBody();

          response.setHeader("Pragma","No-cache");
          response.setHeader("Cache-Control","no-cache");
          response.setDateHeader("Expires", 0);




          每天進步一點點

          posted on 2008-10-24 14:52 應越 閱讀(1053) 評論(2)  編輯  收藏

          評論:
          # re: getOutputStream() has already been called for this response 的解決方法 2009-08-21 20:42 | 藍魚
          受用了!!  回復  更多評論
            
          # re: getOutputStream() has already been called for this response 的解決方法 2010-06-02 15:23 | 007
          try {
          //創建一個帶有路徑的文件
          File f = new File(fileDiskURL+fileName);//getDataExtractPath()

          //創建一個與文件對應的輸入流
          FileInputStream in = new FileInputStream(f);
          //得到一個響應,并對響應進行各種設置
          HttpServletResponse response = ServletActionContext.getResponse();
          response.setContentType("application/octet-stream");
          response.setHeader("Content-Disposition", "attachment; filename=" + new String(fileName.getBytes("ISO-8859-1"),"GBK"));
          //fetch the file
          // OutputStream op = response.getOutputStream();
          // byte[] buf = new byte[in.available()];
          // in.read(buf);
          // op.write(buf);
          // in.close();
          // op.flush();
          // op.close();
          System.out.println("aaaaaaaaaaa11111111111aaaaaaaaaaaaaa");
          int length = (int) f.length();
          if (length != 0) {
          byte[] buf = new byte[4096];
          OutputStream op = response.getOutputStream();
          //把ServletOutputStream 換成 java.io里的outputstream就可以了
          //ServletOutputStream op = response.getOutputStream();
          while ((in != null) && ((length = in.read(buf)) != -1)) {
          op.write(buf, 0, length);
          }
          in.close();
          op.flush();
          op.close();
          }
          return true;
          } catch (FileNotFoundException e) {
          e.printStackTrace();
          return false;
          } catch (IOException e) {
          e.printStackTrace();
          return false;
          }  回復  更多評論
            

          只有注冊用戶登錄后才能發表評論。


          網站導航:
          博客園   IT新聞   Chat2DB   C++博客   博問  
           
          主站蜘蛛池模板: 那坡县| 克东县| 大悟县| 曲松县| 府谷县| 嘉定区| 白银市| 阳谷县| 基隆市| 长海县| 罗源县| 来宾市| 增城市| 丰顺县| 十堰市| 原阳县| 绥阳县| 深水埗区| 邯郸市| 顺平县| 策勒县| 呼图壁县| 巍山| 乳源| 九龙县| 济宁市| 呼伦贝尔市| 体育| 万源市| 南平市| 海兴县| 从化市| 曲阳县| 松溪县| 双流县| 弥渡县| 无锡市| 政和县| 资溪县| 凭祥市| 习水县|