From 5387a90f3a261965c2d2ddb9db786193703c72f9 Mon Sep 17 00:00:00 2001 From: lu Date: Thu, 25 Jul 2024 15:21:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E5=AF=BC=E5=87=BAbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/course/api/CoursePortalApi.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/servers/boe-server-all/src/main/java/com/xboe/module/course/api/CoursePortalApi.java b/servers/boe-server-all/src/main/java/com/xboe/module/course/api/CoursePortalApi.java index f6f605d1..743e91cb 100644 --- a/servers/boe-server-all/src/main/java/com/xboe/module/course/api/CoursePortalApi.java +++ b/servers/boe-server-all/src/main/java/com/xboe/module/course/api/CoursePortalApi.java @@ -399,11 +399,20 @@ public class CoursePortalApi extends ApiBaseController{ } catch (Exception e) { throw new RuntimeException("导出异常"); } - - long totalCompressedSize = 0; String encodedFilename = URLEncoder.encode("作业.zip") .replace("+", "%20") // 空格替换为"%20" .replace("%2F", "/"); // 解决斜杠问题 + StringBuilder contentDispositionValue = new StringBuilder(); + contentDispositionValue.append("attachment; filename=\"") + .append(encodedFilename) + .append("\"") + .append("; filename*=utf-8''") + .append(encodedFilename); + + // 设置响应类型和Content-Disposition头 + response.setContentType("application/zip"); + response.setHeader("Content-Disposition", contentDispositionValue.toString()); + long totalCompressedSize = 0; try (ZipOutputStream zos = new ZipOutputStream(response.getOutputStream())) { for (Map.Entry e : map.entrySet()) { File fileToZip = new File(e.getValue()); @@ -429,16 +438,6 @@ public class CoursePortalApi extends ApiBaseController{ zos.closeEntry(); } - StringBuilder contentDispositionValue = new StringBuilder(); - contentDispositionValue.append("attachment; filename=") - .append(encodedFilename) - .append(";") - .append("filename*=") - .append("utf-8''") - .append(encodedFilename); - // 设置响应类型和Content-Disposition头 - response.setContentType("application/zip"); - response.setHeader("Content-Disposition", contentDispositionValue.toString()); } } @GetMapping("/detail-study")