隨筆-8  評(píng)論-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);




          每天進(jìn)步一點(diǎn)點(diǎn)

          posted on 2008-10-24 14:52 應(yīng)越 閱讀(1055) 評(píng)論(2)  編輯  收藏

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

          //創(chuàng)建一個(gè)與文件對(duì)應(yīng)的輸入流
          FileInputStream in = new FileInputStream(f);
          //得到一個(gè)響應(yīng),并對(duì)響應(yīng)進(jìn)行各種設(shè)置
          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;
          }  回復(fù)  更多評(píng)論
            

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 固阳县| 西乌珠穆沁旗| 连山| 佛山市| 合阳县| 江永县| 平谷区| 邵阳县| 剑川县| 萨迦县| 杨浦区| 潼南县| 湟中县| 中方县| 汶川县| 东兰县| 石棉县| 通江县| 安阳市| 南丰县| 绥宁县| 金坛市| 察雅县| 广东省| 林州市| 秦皇岛市| 陕西省| 利辛县| 盐山县| 启东市| 岳普湖县| 南召县| 教育| 湾仔区| 庄浪县| 莱芜市| 潢川县| 沙田区| 万荣县| 蚌埠市| 宁南县|