safari - Solve safari download Chinese file name garbled characters

The main thing is to set the content-disposition in the response header, which mainly follows the RFC 5987 standard.

The key point is this setting attachment;filename*=UTF-8'' 

For the difference between "filename" and "filename*", please refer to: Content-Disposition

A brief description is as follows:

The final setup is as follows:

response.setHeader("content-disposition","attachment;filename*=UTF-8''" + URLEncoder.encode(fileName,"UTF-8"));

The code is set up as follows:

String originalFileName = URLEncoder.encode("文件名", "utf-8");
response.reset();
response.setHeader("content-disposition", "attachment;filename*=utf-8''" + originalFileName );
response.setContentType("application/octet-stream; charset=utf-8");

Guess you like

Origin blog.csdn.net/qq_34272760/article/details/116533807
Recommended