⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reportservlet.java

📁 WAP PUSH后台源码,WAP PUSH后台源码
💻 JAVA
字号:
package com.sxit.wap.report;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import com.sxit.wap.common.*;
import com.sxit.wap.exception.*;
import com.sxit.wap.admin.AdminBean;
import com.sxit.wap.adminpurview.AdminPurviewBean;

public class ReportServlet extends HttpServlet {
  static final private String CONTENT_TYPE = "text/html; charset=GBK";
  Dict wapDict = null;
  public void init() throws ServletException {
    ServletContext sc = getServletConfig().getServletContext();
    wapDict = (Dict)sc.getAttribute("wapDict");
  }
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try {
      String fileType = request.getParameter("fileType");
      String fileName = request.getParameter("fileName");
      response.setContentType(CONTENT_TYPE);
      if ("excel".equals(fileType)) {
        response.setHeader("Content-disposition", "attachment; filename=" + fileName);
      }
      HttpSession httpSession = request.getSession();
      SessionParam wapParam = (SessionParam)httpSession.getAttribute("wapParam");
      if (wapParam.getAdminInfoModel() == null) return;
      if (!AdminPurviewBean.validPurview(wapParam.getAdminInfoModel(),PurviewCodes.WAP_REPORT)) return;
      String path = "";
      if ("excel".equals(fileType)) {
        path = wapDict.getSystemParamModel().getExcelPath();
      } else {
        path = wapDict.getSystemParamModel().getStatPicturePath();
      }
      outFile(response, path + fileName);
    } catch (Exception e) {
      e.printStackTrace();
      throw new ServletException(e.getMessage());
    }
  }

  public void outFile(HttpServletResponse response, String location) throws IOException {
    BufferedInputStream bis = null;
    BufferedOutputStream bos = null;
    try {
      bis = new BufferedInputStream(new FileInputStream(location));
      bos = new BufferedOutputStream(response.getOutputStream());

      byte[] buff = new byte[2048];
      int bytesRead;

      while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
        bos.write(buff,0,bytesRead);
      }

    } catch(final IOException e) {
      System.out.println ( "出现IOException." + e );
    } finally {
      if (bis != null)
        bis.close();
      if (bos != null)
        bos.close();
    }
  }
  //Clean up resources
  public void destroy() {
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -