gpt4 book ai didi

java - 如何在 Spring 中显示下载文件名中的非法字符?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:30:42 24 4
gpt4 key购买 nike

我下载的文件名为 Ça_r_lar_02_07_2019_12_09.xlsx,但是,我想要它 Çağrılar_02_07_2019_12_09.xlsx。我该如何解决?

try (Workbook workbook = new XSSFWorkbook()) {
new XlsExporter().exportXls(workbook, grh);
SimpleDateFormat sdf = new SimpleDateFormat("_dd_MM_yyyy_HH_mm");
String name = grh.getReportName() + sdf.format(new Date());
response.setContentType(MediaType.APPLICATION_OCTET_STREAM.getType());
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + name + ".xlsx\"");
workbook.write(response.getOutputStream());
response.getOutputStream().flush();
}

最佳答案

在发送响应之前尝试对您的文件名进行 UTF-8 编码

try (Workbook workbook = new XSSFWorkbook()) {
new XlsExporter().exportXls(workbook, grh);
SimpleDateFormat sdf = new SimpleDateFormat("_dd_MM_yyyy_HH_mm");
String name = grh.getReportName() + sdf.format(new Date());
name = URLEncoder.encode(name,"UTF-8");
response.setContentType(MediaType.APPLICATION_OCTET_STREAM.getType());
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + name + ".xlsx\"");
workbook.write(response.getOutputStream());
response.getOutputStream().flush();
}

关于java - 如何在 Spring 中显示下载文件名中的非法字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56849228/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com