|
 /**//*
* 创建日期 2006-1-11
*
* 更改所生成文件模板为
* 窗口 > 首选项 > 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;

 /** *//**
*
* 创建日期:2006-2-9
* 功 能:工作台 > 文档管理 > 文件下载
* @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"); //结束日期
String strUnite_dept = request.getParameter("excel_department_name");//部门
 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 Down 1");
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);
//循环取出流中的数据
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) ;
}
 /** *//**
* 转换上传文件的文件名
* @param sou
* @param ts
* @return String
*/
 private static String buildFilename(String sou) {
 while(sou.indexOf("/") > -1) {
sou = sou.substring(sou.indexOf("/") + 1) ;
}
return sou;
}
}
|