modor
9/20/2017 - 12:41 PM

JavaHandlerFileDownload

 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String filename = "D:\\Document\\music\\Monica.mp3";
        String contentType = this.getServletContext().getMimeType(filename);
        String contentDisposition = "attachment;filename=Monica.mp3";
        FileInputStream input = new FileInputStream(filename);
        response.setHeader("Content-Type", contentType);
        response.setHeader("Content-Disposition", contentDisposition);
        ServletOutputStream output = response.getOutputStream();
        IOUtils.copy(input,output);
        input.close();
    }