コード例 #1
0
  private void displayPage(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    String zipFileName = request.getParameter("zipFileName");
    if ("null".equals(zipFileName)) {
      zipFileName = null;
    }

    request.setAttribute("zipFileName", zipFileName);
    request.setAttribute("fileLocation", fileService.getFilePath());
    RequestDispatcher requestDispatcher = request.getRequestDispatcher("jsp/welcomeJsp.jsp");
    requestDispatcher.forward(request, response);
  }
コード例 #2
0
  private void handleLinkDownload(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    String zipFileName = request.getParameter("zipFileName");
    String filePath = fileService.getFilePath();
    String fileLocation = filePath + zipFileName;

    InputStream is = new FileInputStream(new File(fileLocation));
    OutputStream os = response.getOutputStream();

    ZipInputStream zis = new ZipInputStream(is);
    ZipEntry ze = zis.getNextEntry();
    String fileName = ze.getName();

    response.setContentType("application/octet-stream");
    response.setHeader("Content-Disposition", "attachment;filename=" + fileName);

    try {
      fileService.writeFile(zis, os);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }