程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> java js-java servlet這是單個下載,怎麼打包批量下載

java js-java servlet這是單個下載,怎麼打包批量下載

編輯:編程綜合問答
java servlet這是單個下載,怎麼打包批量下載

package cn.szusst.aqms.action.common;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.io.OutputStream;

import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

/**

  • Servlet implementation class ServletDownload
    */

    @WebServlet(asyncSupported = true, urlPatterns = { "/ServletDownload" })

    public class ServletDownload extends HttpServlet {

    private static final long serialVersionUID = 1L;

    /**

    • @see HttpServlet#HttpServlet() */
      public ServletDownload() {
      super();
      // TODO Auto-generated constructor stub
      }

    /**

    • @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
      */

      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

      response.setContentType("application/x-msdownload");
      // TODO Auto-generated method stub

      //獲得請求文件名

      String filename = request.getParameter("filename");

      //設置文件MIME類型

      response.setContentType(getServletContext().getMimeType(filename));

      //設置Content-Disposition

      response.setHeader("Content-Disposition", "attachment;filename="+filename);

      //讀取目標文件,通過response將目標文件寫到客戶端

      //獲取目標文件的絕對路徑

      // //讀取文件

      OutputStream out = response.getOutputStream();

      String fullFileName = filename;
      InputStream in = new FileInputStream(fullFileName);

      //寫文件

      int b;

      while((b=in.read())!= -1)

      {

      out.write(b);

      }

      in.close();

      // out.close();

      }

    /**

    • @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      // TODO Auto-generated method stub
      }

}

最佳回答:


這是百度上搜的呀圖片說明

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved