文件下载


实现方式:

超链接实现

代码实现

通过response输出流将数据写到客户端

设置响应头:content-dispositionattachment;filename=xxx.jpg

/**

* 设置一个响应头,然后给定两个流,一个是输入流一个是输出流

* 一个头两个流

*/

  response.setHeader("content-disposition", "attachment;filename=mv.jpg" );

      //+ new String("哈哈.jpg".getBytes("GBK") , "iso8859-1")) ;

      response.setHeader("content-disposition", "attachment;filename=+ new String("哈哈.jpg".getBytes("GBK") , "iso8859-1")) ; 

      //如果是汉字的处理方式

                   String path = getServletContext().getRealPath("/mv.jpg") ;

                   FileInputStream fis = new FileInputStream(path) ;

                   ServletOutputStream out = response.getOutputStream() ;

                   IOUtils.copy(fis, out) ;
原文地址:https://www.cnblogs.com/loaderman/p/6415503.html