In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is to share with you about the java file download file name garbled solution is what, the editor feels very practical, so share with you to learn, I hope you can get something after reading this article, say no more, follow the editor to have a look.
There are two cases of garbled code when downloading JAVA files:
1. The Chinese file name is garbled when downloading
2. When downloading, the file cannot be found because the path contains garbled Chinese file names
For the solution, see the following section of code
Response.setContentType ("multipart/form-data")
String userAgent = request.getHeader ("User-Agent")
String oraFileName = meetingFile.getFileName ()
String formFileName=oraFileName
/ / for browsers with IE or IE as the core:
If (userAgent.contains ("MSIE") | | userAgent.contains ("Trident")) {
FormFileName = java.net.URLEncoder.encode (formFileName, "UTF-8")
}
Else {
/ / processing of non-IE browsers: formFileName = new String (formFileName.getBytes ("UTF-8"), "ISO-8859-1");}
Response.setHeader ("Content-disposition"
String.format ("attachment; filename=\"% s\ ", formFileName))
Response.setContentType ("application/vnd.ms-excel;charset=utf-8")
Response.setCharacterEncoding ("UTF-8")
ServletOutputStream out; /
/ get the File object through the file path
File file = null
If (meetingFile! = null) {
File = new File (path + "upload/" + oraFileName)
}
(1) if the first type of garbled code, the download page encounters the following Chinese garbled problem
Solve the problem with the following code
(2) if the download encounters the second garbled code problem, as shown in the figure:
Solve the problem with the following code: first, make sure that tomcat, eclipse, etc., encode utf-8.
Then this is separated from the first encoding of file names in JAVA so that they are encoded separately and do not affect each other.
Note: previous tests can solve the coding problem when downloading browsers such as Firefox and IE.
The above is the solution to the problem of garbled names in downloading java files. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.