注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

风之泪

风过雨过,花开花落。。。

 
 
 

日志

 
 

JAVA导出excel报表  

2010-09-21 10:35:55|  分类: fileopera |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

package com.xdgd.epos.servlet;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

import com.xdgd.epos.exception.NewDBBeanException;
import com.xdgd.epos.exception.findDBFailException;
import com.xdgd.epos.pojo.Mer_TransBean;
import com.xdgd.epos.table.Acl;
import com.xdgd.epos.table.Mer_Trans;
import com.xdgd.epos.table.Merchant;
import com.xdgd.epos.table.Users;
import com.xdgd.epos.utils.ExportExcel;

/**
 *
 * 报表Servlet类
 */
public class ReportServlet extends HttpServlet {
 private static final long serialVersionUID = 1L;
 public static final Logger logger = Logger.getLogger(ReportServlet.class);

 @Override
 protected void doGet(HttpServletRequest req, HttpServletResponse resp)
   throws ServletException, IOException {
  String uri = req.getRequestURI();
  String ctx = req.getContextPath();
  uri = uri.substring(ctx.length());
  String method = req.getParameter("method");
  String sheetName = "商户交易信息";
  String[] title = { "订单号", "建档时间", "商戶号", "交易金额", "订单状态", "商户日期", "网关号",
    "交易类型", "货币类型号", "银行应答代码", "商户私有域", "交易状态", "终端", "对帐日期",
    "对账状态" };
  HttpSession session = req.getSession();
  Date beginDate = null;
  Date endDate = null;
  String cxtPath = req.getContextPath();
  String basePath = req.getScheme() + "://" + req.getServerName() + ":"
    + req.getServerPort() + cxtPath + "/";
  synchronized (session) {
   String merId = (String) session.getAttribute("merID");
   Users user = (Users) session.getAttribute("login");
   String userName = user.getUserName();
   /**
    * 跳转到导出商户历史交易信息页面
    */
   if ("toExportHisExcel".equals(method)) {
    try {
     boolean value = Acl.OperatorRightModules(user.getUserId(),
       uri + "?method=toExportHisExcel");
     if (value == false) {
      req.getRequestDispatcher("../NoPrivilege.jsp").forward(
        req, resp);
      return;
     }
    } catch (findDBFailException e1) {
     e1.printStackTrace();
    }
    req.getRequestDispatcher("../reportManager/exportHisExcel.jsp")
      .forward(req, resp);
   }

   /**
    * 跳转到导出商户历史交易信息页面
    */
   if ("findAllTrans".equals(method)) {
    try {
     boolean value = Acl.OperatorRightModules(user.getUserId(),
       uri + "?method=findAllTrans");
     if (value == false) {
      req.getRequestDispatcher("../NoPrivilege.jsp").forward(
        req, resp);
      return;
     }
    } catch (findDBFailException e1) {
     e1.printStackTrace();
    }
    int currPage;
    int pageSize;
    if (req.getParameter("currPage") != null
      && !"".equals(req.getParameter("currPage"))) {
     currPage = Integer.valueOf(req.getParameter("currPage"));
    } else {
     currPage = 1;
    }

    if (req.getParameter("pageSize") != null
      && !"".equals(req.getParameter("pageSize"))) {
     pageSize = Integer.valueOf(req.getParameter("pageSize"));
    } else {
     pageSize =200;
    }
    req.setAttribute("currPage", currPage);
    req.setAttribute("pageSize", pageSize);
    try {
     Mer_Trans mer_Trans=new Mer_Trans();
     int balcStatus=Integer.valueOf(req.getParameter("balcStatus"));
     int transStatus=Integer.valueOf(req.getParameter("transStatus"));
     req.setAttribute("balcStatus", balcStatus);
     req.setAttribute("transStatus", transStatus);
     List<Mer_TransBean> list = mer_Trans.findAllMer_TransByPage(null,
       currPage, pageSize,null,null,2,balcStatus,transStatus);
     int count = Mer_Trans.findTransCount();
     req.setAttribute("count", count);
     if (count % pageSize > 0) {
      req.setAttribute("maxPage", count / pageSize + 1);
     } else {
      req.setAttribute("maxPage", count / pageSize);
     }

     req.setAttribute("transList", list);

    } catch (findDBFailException e) {
     e.printStackTrace();
    }
    req.getRequestDispatcher(
      "../reportManager/showAllTransactions.jsp").forward(
      req, resp);
   }

   /**
    * 跳转到导出商户当前交易信息页面
    */
   if ("toExportCurrExcel".equals(method)) {
    try {
     boolean value = Acl.OperatorRightModules(user.getUserId(),
       uri + "?method=toExportCurrExcel");
     if (value == false) {
      req.getRequestDispatcher("../NoPrivilege.jsp").forward(
        req, resp);
      return;
     }
    } catch (findDBFailException e1) {
     e1.printStackTrace();
    }
    req
      .getRequestDispatcher(
        "../reportManager/exportCurrExcel.jsp")
      .forward(req, resp);
   }

   /**
    * 导出商户历史交易信息,下载到指定位置后删除服务器上的文件
    */
   if ("exportHisExcel".equals(method)) {
    try {
     boolean value = Acl.OperatorRightModules(user.getUserId(),
       uri + "?method=exportHisExcel");
     if (value == false) {
      req.getRequestDispatcher("../NoPrivilege.jsp").forward(
        req, resp);
      return;
     }
    } catch (findDBFailException e1) {
     e1.printStackTrace();
    }
    java.text.SimpleDateFormat formatStr = new java.text.SimpleDateFormat(
      "yyyy-MM-dd", Locale.CHINA);
    java.text.SimpleDateFormat formatDate = new java.text.SimpleDateFormat(
      "yyyy年MM月dd日", Locale.CHINA);
    String xls_name = null;
    try {
     if (req.getParameter("beginDate") != null
       && req.getParameter("beginDate") != "") {
      java.util.Date bDate = formatStr.parse(req
        .getParameter("beginDate"));
      java.util.Date eDate = formatStr.parse(req
        .getParameter("endDate"));
      xls_name = formatDate.format(bDate) + "-"
        + formatDate.format(eDate);
     }
    } catch (ParseException e1) {
     e1.printStackTrace();
    }
    String type = (String) req.getParameter("exportType");
    String merName = null;
    String url = getServletContext().getRealPath("/");
    String dir = url + "download\\" + userName + "\\";
    String path = dir + xls_name;
    if (merId == null) {
     if ("single".equals(type)) {
      merId = req.getParameter("merId");
      try {
       Merchant merchant = new Merchant(merId);
       merName = merchant.getMerName();
       path = path + merName;
      } catch (NewDBBeanException e) {
       e.printStackTrace();
      }
     } else {
      merId = null;
      merName = "所有";
      path = path + merName;
     }
    }
    path = path + "商户历史消费记录表.xls";
    if(req.getParameter("beginDate")!=null&& req.getParameter("beginDate") != ""){
     beginDate = java.sql.Date
     .valueOf(req.getParameter("beginDate"));
    }
    if(req.getParameter("endDate")!=null){
     endDate = java.sql.Date.valueOf(req.getParameter("endDate"));
    }
    
    ExportExcel export = new ExportExcel();

    File filedir = new File(dir);
    if (!filedir.exists()) {
     filedir.mkdirs();
    }

    File file = new File(path);
    OutputStream os = null;
    try {
     try {
      os = new FileOutputStream(file);
     } catch (FileNotFoundException e) {
      e.printStackTrace();
     }
     int balcStatus=0;
     int transStatus=0;
     if(req.getParameter("balcStatus")!=null||req.getParameter("balcStatus")!=""){
      balcStatus=Integer.valueOf(req.getParameter("balcStatus"));
     }
     if(req.getParameter("transStatus")!=null||req.getParameter("transStatus")!=""){
      transStatus=Integer.valueOf(req.getParameter("transStatus"));
     }
     List<Mer_TransBean> list = Mer_Trans.findAllMer_Trans(
       merId, beginDate, endDate, 1,balcStatus,transStatus);
     int size=0;
     if(list==null){
      
     }else{
      size=list.size();
     }
     String message = null;
     message = "总计:" + size+ "条。 生成条件:导出从"
       + req.getParameter("beginDate") + "到"
       + req.getParameter("endDate") + "的交易";
     logger.info(user.getUserName() + "开始导出商户[" + beginDate
       + "-" + endDate + "]历史交易信息!");
     export.exportExcel(os, sheetName, message, title, list);

     // 客户端下载时显示的名称
     String filenamedisplay = "商户消费记录表.xls";

     // 生成文件的文件名(绝对路径)
     // 获取前台传入的参数
     filenamedisplay = URLEncoder.encode(filenamedisplay,
       "UTF-8");
     resp.reset();
     resp.setContentType("application/x-msdownload");
     resp.addHeader("Content-Disposition",
       "attachment;filename=" + filenamedisplay);
     OutputStream output = resp.getOutputStream();
     FileInputStream fis = new FileInputStream(path);
     byte[] b = new byte[1024];
     int i = 0;
     while ((i = fis.read(b)) > 0) {
      output.write(b, 0, i);
     }
     logger.info(user.getUserName() + "导出商户[" + beginDate + "-"
       + endDate + "]历史交易信息成功!");
     output.flush();
     fis.close();
     output.close();
     if (file.exists()) {
      file.delete();
     }
    } catch (Exception e) {
     e.printStackTrace();
    } finally {
     os.flush();
     os.close();
    }
   }

   /**
    * 分页查询商户历史交易信息
    */
   if ("searchHisTrans".equals(method)||"trans".equals(method)) {
    try {
     boolean value = Acl.OperatorRightModules(user.getUserId(),
       uri + "?method=searchHisTrans");
     if (value == false) {
      req.getRequestDispatcher("../NoPrivilege.jsp").forward(
        req, resp);
      return;
     }
    } catch (findDBFailException e1) {
     e1.printStackTrace();
    }

    String type = (String) req.getParameter("type");
    if (merId == null) {
     if ("single".equals(type)) {
      merId = req.getParameter("merId");
      req.setAttribute("merId", merId);
     } else {
      merId = null;
     }
    }
    
    if(req.getParameter("beginDate")!=null&&!"".equals(req.getParameter("beginDate"))){
     beginDate = java.sql.Date
     .valueOf(req.getParameter("beginDate"));
    }
    if(req.getParameter("endDate")!=null){
     endDate = java.sql.Date.valueOf(req.getParameter("endDate"));
    }
    int balcStatus=Integer.valueOf(req.getParameter("balcStatus"));
    int transStatus=Integer.valueOf(req.getParameter("transStatus"));
    req.setAttribute("balcStatus", balcStatus);
    req.setAttribute("transStatus", transStatus);
    req.setAttribute("type", req.getParameter("type"));
    try {
     /**
      * 分页的查询
      */
     int currPage;
     int pageSize;
     if (req.getParameter("currPage") != null
       && !"".equals(req.getParameter("currPage"))) {
      currPage = Integer.valueOf(req.getParameter("currPage"));
     } else {
      currPage = 1;
     }

     if (req.getParameter("pageSize") != null
       && !"".equals(req.getParameter("pageSize"))) {
      pageSize = Integer.valueOf(req.getParameter("pageSize"));
     } else {
      pageSize = 200;
     }
     req.setAttribute("currPage", currPage);
     req.setAttribute("pageSize", pageSize);
     req.setAttribute("beginDate", beginDate);
     req.setAttribute("endDate", endDate);
     try {
      Mer_Trans mer_Trans=new Mer_Trans();
      List<Mer_TransBean> list = mer_Trans.findAllMer_TransByPage(merId,
        currPage, pageSize,beginDate,endDate,1,balcStatus,transStatus);
      int count = Mer_Trans.findHisTransCount(merId, beginDate, endDate,balcStatus,transStatus);
      req.setAttribute("count", count);
      if (count % pageSize > 0) {
       req.setAttribute("maxPage", count / pageSize + 1);
      } else {
       req.setAttribute("maxPage", count / pageSize);
      }

      req.setAttribute("hisTransList", list);

     } catch (findDBFailException e) {
      e.printStackTrace();
     }

    } catch (Exception e) {
     e.printStackTrace();
    }
    req.getRequestDispatcher("../reportManager/exportHisExcel.jsp")
      .forward(req, resp);
   }

   /**
    * 导出商户当前交易信息,下载到指定位置后删除服务器上的文件
    */
   if ("exportCurrExcel".equals(method)) {
    try {
     boolean value = Acl.OperatorRightModules(user.getUserId(),
       uri + "?method=exportCurrExcel");
     if (value == false) {
      req.getRequestDispatcher("../NoPrivilege.jsp").forward(
        req, resp);
      return;
     }
    } catch (findDBFailException e1) {
     e1.printStackTrace();
    }
    java.util.Date sysDate = new java.util.Date();
    java.text.SimpleDateFormat format = new java.text.SimpleDateFormat(
      "yyyy年MM月dd日 hh时mm分ss秒", Locale.CHINA);
    String merName = null;
    String day = format.format(sysDate);
    if (("single").equals(req.getParameter("exportType"))) {
     merId = req.getParameter("merId");
     try {
      Merchant merchant = new Merchant(merId);
      merName = merchant.getMerName();
     } catch (NewDBBeanException e) {
      e.printStackTrace();
     }
    } else {
     merName = "所有";
     merId = null;
    }

    ExportExcel export = new ExportExcel();
    String url = getServletContext().getRealPath("/");
    String dir = url + "download\\" + userName + "\\";
    File filedir = new File(dir);
    if (!filedir.exists()) {
     filedir.mkdirs();
    }
    String path = dir + day + "商户当前消费记录表.xls";
    File file = new File(path);
    OutputStream os = null;
    try {
     try {
      os = new FileOutputStream(file);
     } catch (FileNotFoundException e) {
      e.printStackTrace();
     }
     int balcStatus=Integer.valueOf(req.getParameter("balcStatus"));
     int transStatus=Integer.valueOf(req.getParameter("transStatus"));
     List<Mer_TransBean> list = Mer_Trans.findAllMer_Trans(
       merId, beginDate, endDate, 0,balcStatus,transStatus);
     String message = null;
     java.text.SimpleDateFormat formatDate = new java.text.SimpleDateFormat(
       "yyyy年MM月dd日 hh时mm分ss秒", Locale.CHINA);
     String time = formatDate.format(new java.util.Date());
     message = "总计:" + list.size()
       + "条。 生成条件:导出当天到指定时间的交易信息,导出时间为:" + time;
     logger.info(user.getUserName() + "开始导出截止【" + time
       + "】的当天交易信息");
     export.exportExcel(os, sheetName, message, title, list);
     // 客户端下载时显示的名称
     String filenamedisplay = "商户消费记录表.xls";

     // 生成文件的文件名(绝对路径)
     // 获取前台传入的参数
     filenamedisplay = URLEncoder.encode(filenamedisplay,
       "UTF-8");
     resp.reset();
     resp.setContentType("application/x-msdownload");
     resp.addHeader("Content-Disposition",
       "attachment;filename=" + filenamedisplay);
     OutputStream output = resp.getOutputStream();
     FileInputStream fis = new FileInputStream(path);
     byte[] b = new byte[1024];
     int i = 0;
     while ((i = fis.read(b)) > 0) {
      output.write(b, 0, i);
     }
     logger.info(user.getUserName() + "导出截止【" + time
       + "】的当天交易信息成功!");
     output.flush();
     fis.close();
     output.close();
     if (file.exists()) {
      file.delete();
     }
    } catch (Exception e) {
     e.printStackTrace();
    } finally {
     os.flush();
     os.close();
    }
   }

   /**
    * 查询商户当前交易信息
    */
   if ("searchCurrTrans".equals(method)) {
    try {
     boolean value = Acl.OperatorRightModules(user.getUserId(),
       uri + "?method=searchCurrTrans");
     if (value == false) {
      req.getRequestDispatcher("../NoPrivilege.jsp").forward(
        req, resp);
      return;
     }
    } catch (findDBFailException e1) {
     e1.printStackTrace();
    }

    if (("single").equals(req.getParameter("exportType"))) {
     merId = req.getParameter("merId");
     req.setAttribute("merId", merId);
    } else {
     merId = null;
    }
    req.setAttribute("type", req.getParameter("exportType"));
     /**
      * 分页的查询
      */
     int currPage;
     int pageSize;
     if (req.getParameter("currPage") != null
       && !"".equals(req.getParameter("currPage"))) {
      currPage = Integer.valueOf(req.getParameter("currPage"));
     } else {
      currPage = 1;
     }

     if (req.getParameter("pageSize") != null
       && !"".equals(req.getParameter("pageSize"))) {
      pageSize = Integer.valueOf(req.getParameter("pageSize"));
     } else {
      pageSize = 200;
     }
     req.setAttribute("currPage", currPage);
     req.setAttribute("pageSize", pageSize);
     try {
      Mer_Trans mer_Trans=new Mer_Trans();
      int balcStatus=Integer.valueOf(req.getParameter("balcStatus"));
      int transStatus=Integer.valueOf(req.getParameter("transStatus"));
      req.setAttribute("balcStatus", balcStatus);
      req.setAttribute("transStatus", transStatus);
      List<Mer_TransBean> list = mer_Trans.findAllMer_TransByPage(merId,
        currPage, pageSize,null,null,0,balcStatus,transStatus);
      int count = Mer_Trans.findCurrTransCount(merId,balcStatus,transStatus);
      req.setAttribute("count", count);
      if (count % pageSize > 0) {
       req.setAttribute("maxPage", count / pageSize + 1);
      } else {
       req.setAttribute("maxPage", count / pageSize);
      }

      req.setAttribute("currTransList", list);

     } catch (findDBFailException e) {
      e.printStackTrace();
     }

    RequestDispatcher rd=req.getRequestDispatcher("../reportManager/exportCurrExcel.jsp");
    rd.forward(req, resp);
    
   }

   /**
    * 导出商户交易信息
    */
   if ("exportExcel".equals(method)) {
    System.out.println("ExportExcel");
    try {
     boolean value = Acl.OperatorRightModules(user.getUserId(),
       uri + "?method=exportExcel");
     if (value == false) {
      req.getRequestDispatcher("../NoPrivilege.jsp").forward(
        req, resp);
      return;
     }
    } catch (findDBFailException e1) {
     e1.printStackTrace();
    }
    List<Mer_TransBean> transList=new ArrayList<Mer_TransBean>();
    java.text.SimpleDateFormat format = new java.text.SimpleDateFormat(
      "yyyy-MM-dd hh:mm:ss", Locale.CHINA);
    try {
     int count=200;
     double money=0;
     if(req.getParameter("count")!=null&&req.getParameter("count")!=""){
      count=Integer.parseInt(req.getParameter("count"));
     }
     if(req.getParameter("money")!=null&&req.getParameter("money")!=""){
      money=Double.parseDouble(req.getParameter("money"));
     }
     if(req.getParameter("beginDate")!=null&&req.getParameter("beginDate")!=""){
      beginDate=format.parse(new String(req.getParameter("beginDate").getBytes("iso-8859-1")));
      transList=Mer_Trans.findNowMer_Trans(beginDate,count,money);
      req.setAttribute("transList", transList);
      req.setAttribute("beginDate", new String(req.getParameter("beginDate").getBytes("iso-8859-1")));
     }else{
      
     }
     
    } catch (ParseException e1) {
     e1.printStackTrace();
    }catch (findDBFailException e) {
     e.printStackTrace();
    }
    String xls_name = null;
    String type = (String) req.getParameter("exportType");
    String merName = null;
    ExportExcel export = new ExportExcel();
    String url = getServletContext().getRealPath("/");
    String path = url + "商户消费记录表.xls";
    File file = new File(path);
    try {
     OutputStream os = null;
     try {
      os = new FileOutputStream(file);
     } catch (FileNotFoundException e) {
      e.printStackTrace();
     }
     String message = null;
     java.text.SimpleDateFormat formatDate = new java.text.SimpleDateFormat(
       "yyyy年MM月dd日 hh时mm分ss秒", Locale.CHINA);
     String time = formatDate.format(new java.util.Date());
     message = "总计:"
       + transList.size()
       + "条。 生成条件:导出"
       + new String(req.getParameter("beginDate")
         .getBytes("iso-8859-1")) + "开始的交易信息,导出时间为:"
       + time;
     export
       .exportExcel(os, sheetName, message, title,
         transList);
     req.getSession().setAttribute("url", path);
     if (merName == null) {
      req.getSession().setAttribute("xls_name",
        "所有商户--" + xls_name);
     } else {
      req.getSession().setAttribute("xls_name",
        merName + "--" + xls_name);
     }
     os.close();
     // 客户端下载时显示的名称
     String filenamedisplay = "商户消费记录表.xls";

     // 生成文件的文件名(绝对路径)

     String filenamedownload = (String) req.getSession()
       .getAttribute("url");
     filenamedisplay = URLEncoder.encode(filenamedisplay,
       "UTF-8");
     resp.reset();
     resp.setContentType("application/x-msdownload");
     resp.addHeader("Content-Disposition",
       "attachment;filename=" + filenamedisplay);
     OutputStream output = resp.getOutputStream();
     FileInputStream fis = new FileInputStream(filenamedownload);
     byte[] b = new byte[1024];
     int i = 0;
     while ((i = fis.read(b)) > 0) {
      output.write(b, 0, i);
     }
     output.flush();
     fis.close();
     output.close();
     if (file.exists()) {
      file.delete();
     }
    } catch (Exception e) {
     e.printStackTrace();
    }

   }

   /**
    * 下载并删除Excel报表
    */
   if ("downExcel".equals(method)) {
    try {
     boolean value = Acl.OperatorRightModules(user.getUserId(),
       uri + "?method=downExcel");
     if (value == false) {
      req.getRequestDispatcher("../NoPrivilege.jsp").forward(
        req, resp);
      return;
     }
    } catch (findDBFailException e1) {
     e1.printStackTrace();
    }
    // 客户端下载时显示的名称
    String filenamedisplay = "商户消费记录表.xls";

    // 生成文件的文件名(绝对路径)
    // 获取前台传入的参数
    byte[] info = req.getParameter("url").getBytes("iso-8859-1");
    String filenamedownload = new String(info);
    filenamedisplay = URLEncoder.encode(filenamedisplay, "UTF-8");
    resp.reset();
    resp.setContentType("application/x-msdownload");
    resp.addHeader("Content-Disposition", "attachment;filename="
      + filenamedisplay);
    OutputStream output = resp.getOutputStream();
    FileInputStream fis = new FileInputStream(filenamedownload);
    byte[] b = new byte[1024];
    int i = 0;
    while ((i = fis.read(b)) > 0) {
     output.write(b, 0, i);
    }
    output.flush();
    fis.close();
    output.close();
    File file = new File(filenamedownload);
    if (file.exists()) {
     file.delete();
    }
   }

   // 导出商户信息
   if ("exportExcelInfo".equals(method)) {
    OutputStream os = null;
    OutputStream output = null;
    FileInputStream fis = null;
    try {
     boolean value = Acl.OperatorRightModules(user.getUserId(),
       uri + "?method=exportExcelInfo");
     if (value == false) {
      req.getRequestDispatcher("../NoPrivilege.jsp").forward(
        req, resp);
      return;
     }
    } catch (findDBFailException e1) {
     e1.printStackTrace();
    }
    try {
     merId = req.getParameter("merID");
     Merchant merchant = new Merchant(merId);
     ExportExcel export = new ExportExcel();
     String url = getServletContext().getRealPath("/");
     String path = url + "merchantExcel//";
     File file = new File(path);
     if (!file.exists()) {
      file.mkdir();
     }
     path = path + "商户" + merId + "的个人信息.xls";
     file = new File(path);
     try {
      os = new FileOutputStream(file);
     } catch (FileNotFoundException e) {
      e.printStackTrace();
     }
     String[] menu = { "商户号", "商户别名", "密码", "联络人", "联系电话",
       "商户地址", "银行账号", "扣率" };
     String message = "商户的信息";
     export.exportMerchantExcel(os, sheetName, message, menu,
       merchant);
     // 客户端下载时显示的名称
     String filenamedisplay = "商户个人信息表.xls";
     resp.reset();
     resp.setContentType("application/x-msdownload");
     filenamedisplay = URLEncoder.encode(filenamedisplay,
       "UTF-8");
     resp.addHeader("Content-Disposition",
       "attachment;filename=" + filenamedisplay);
     output = resp.getOutputStream();
     fis = new FileInputStream(path);
     byte[] b = new byte[1024];
     int i = 0;
     while ((i = fis.read(b)) > 0) {
      output.write(b, 0, i);
     }
     output.flush();

     File filedelete = new File(path);
     if (filedelete.exists()) {
      filedelete.delete();
     }
    } catch (NewDBBeanException e) {
     e.printStackTrace();
    } finally {
     fis.close();
     output.close();
     os.close();
    }

   }
  }
 }

 @Override
 protected void doPost(HttpServletRequest req, HttpServletResponse resp)
   throws ServletException, IOException {
  doGet(req, resp);
 }

}

  评论这张
 
阅读(2523)| 评论(3)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017