The solution to the problem of garbled file names downloaded from java files (transfer)

In Java web development, the problem of garbled file names in the file download function is often encountered.

For this problem, different browsers have different solutions.

For IE, use URLEncoder to encode the filename in UTF8.

Other browsers (firefox, chrome, safari, opera) need to convert bytes to ISO8859-1.

Sample code (passed the test ):

 

[java]  view plain copy  
 
  1. if (request.getHeader("User-Agent").toUpperCase().indexOf("MSIE") > 0) {  
  2.     filename = URLEncoder.encode(filename, "UTF-8");  
  3. else {  
  4.     filename = new String(filename.getBytes("UTF-8"), "ISO8859-1");  
  5. }  

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327043522&siteId=291194637