隨筆 - 15, 文章 - 0, 評(píng)論 - 11, 引用 - 0
          數(shù)據(jù)加載中……

          程序下載java程序

            /*
           * 創(chuàng)建日期 2006-1-11
           *
           * 更改所生成文件模板為
           * 窗口 > 首選項(xiàng) > Java > 代碼生成 > 代碼和注釋
           
          */

          package com.abc.cc.util.file ;

          import javax.servlet.http.HttpServlet;
          import javax.servlet.http.HttpServletRequest;
          import javax.servlet.http.HttpServletResponse;

          import javax.servlet.ServletOutputStream;
          import java.io.FileInputStream;

          import com.abc.callcenter.DataStatistic.Export.CreatUDStatisticExport;
          import com.abc.callcenter.uds.unitedealwith.UniteUtil;

          /**
           * 
           * 創(chuàng)建日期:2006-2-9
           * 功  能:工作臺(tái) > 文檔管理 > 文件下載
           * 
          @author asx
           *
           
          */

          public class Down extends HttpServlet {
              
          public void doGet(HttpServletRequest request , HttpServletResponse response) {
                  System.out.println(
          "logining Down");
                  response.setContentType(
          "text/html; charset=GBK");
                  String downfile 
          = request.getRealPath("/"+ "/exportfile/" + TimeTool.getCurrentDateForEight() + "_" + StringTool.getExportFileName(Integer.parseInt(request.getParameter("fileName"))) ;
                  
          try {downfile = new String(downfile.getBytes("GBK")) ;}catch(Exception e){}
                  System.out.println(
          "downfile = "+downfile);
                  String fileName 
          = buildFilename(downfile) ;
                  System.out.println(
          "fileName = "+fileName);
                  
                  String strBeginDate 
          = request.getParameter("excel_begindate"); //起始日期
                  String strEndDate = request.getParameter("excel_enddate"); //結(jié)束日期
                  String strUnite_dept = request.getParameter("excel_department_name");//部門(mén)
                  try{
                      strUnite_dept 
          = UniteUtil.Query_NameDepartment(""+strUnite_dept);;
                  }
          catch(Exception e){
                      e.printStackTrace();
                  }
              
                  CreatUDStatisticExport cue 
          = new CreatUDStatisticExport();
                  cue.queryPrintInfo(strBeginDate,strEndDate,strUnite_dept,request);
                  
                  System.out.println(
          "logining Down1");
                  
          try 
                  

                      fileName
          =response.encodeURL(new String(fileName.getBytes(),"iso-8859-1"));
                      response.reset(); 
                      response.setContentType(
          "APPLICATION/OCTET-STREAM"); 
                      response.setHeader(
          "Content-Disposition""attachment; filename=\"" + fileName + "\""); 
                      ServletOutputStream out 
          = response.getOutputStream(); 
                      FileInputStream inStream 
          = new FileInputStream(downfile); 
                      
                      
          //循環(huán)取出流中的數(shù)據(jù) 
                      byte[] b = new byte[1024]; 
                      
          int len; 
                      
          while((len=inStream.read(b , 0 , b.length)) >0{
                          out.write(b,
          0,len);                 
                      }

                      out.close(); 
                      inStream.close(); 
                  }
           catch(Exception e) {}
              }

              
          public void doPost(HttpServletRequest request , HttpServletResponse response) {
                  doGet(request , response) ;
              }

              
              
          /**
               * 轉(zhuǎn)換上傳文件的文件名
               * 
          @param sou
               * 
          @param ts
               * 
          @return String
               
          */

              
          private static String buildFilename(String sou) {
                  
          while(sou.indexOf("/"> -1{
                      sou 
          = sou.substring(sou.indexOf("/"+ 1) ;
                  }

                  
          return sou;
              }

          }

          posted on 2007-08-01 15:23 軒轅 閱讀(249) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): java

          主站蜘蛛池模板: 和平县| 吉林省| 古浪县| 乾安县| 德昌县| 柏乡县| 天镇县| 大同县| 临泉县| 铅山县| 神农架林区| 柏乡县| 个旧市| 蓬溪县| 中山市| 南昌县| 江山市| 宁河县| 达州市| 青神县| 宝山区| 哈尔滨市| 门源| 南漳县| 普洱| 万盛区| 颍上县| 潞西市| 房产| 日土县| 东城区| 吉水县| 南宁市| 泾川县| 石嘴山市| 松原市| 磐安县| 亳州市| 塔河县| 宝山区| 海淀区|