| | |
| | | import java.net.URLEncoder; |
| | | import java.sql.Timestamp; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.Random; |
| | | import java.util.UUID; |
| | | |
| | |
| | | * @throws Exception 异常 |
| | | */ |
| | | public static void download(String file, String fileName, HttpServletResponse res) throws Exception { |
| | | if (StringHelper.isNull(fileName)) { |
| | | fileName = URLEncoder.encode(FileHelper.getFileName(file), "UTF-8"); |
| | | if (StringHelper.isEmpty(fileName)) { |
| | | fileName = StringHelper.YMDHMS2_FORMAT.format(new Date()); |
| | | } |
| | | fileName = URLEncoder.encode(fileName, "UTF-8").replace("+", "%20"); |
| | | |
| | | // 设置响应头中文件的下载方式为附件方式,以及设置文件名 |
| | | res.setHeader("Content-Disposition", "attachment; filename=" + fileName); |
| | | // 设置响应头的编码格式为UTF-8 |
| | | res.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + fileName); |
| | | // 设置响应头的编码格式为 UTF-8 |
| | | res.setCharacterEncoding("UTF-8"); |
| | | |
| | | // 通过response对象设置响应数据格式(如:"text/plain; charset=utf-8") |