String fileName; String userAgent = request.getHeader("user-agent").toLowerCase(); if(userAgent.contains("msie") || userAgent.contains("like gecko")){//解决IE下载的文件中中文乱码问题 fileName = URLEncoder.encode(pdfFileName, "UTF-8"); }else{ fileName = new String(pdfFileName.getBytes(), "iso8859-1"); } //将文件流返回给客户端 response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment; filename=" + fileName); try (ServletOutputStream sos = response.getOutputStream()) { sos.write(result); }