Servlet technology needs to re-encode the file name when downloading Chinese name attachments
for example:
if (agent.contains("MSIE")) {
// IE
filename = URLEncoder.encode(filename, "utf-8");
filename = filename.replace("+", " ");
} else if (agent.contains("Firefox")) {
//
BASE64Encoder base64Encoder = new BASE64Encoder();
filename = "=?utf-8?B?"
+ base64Encoder.encode(filename.getBytes("utf-8")) + "?=";
} else {
//
filename = URLEncoder.encode(filename, "utf-8");
}
agentUser-Agent
uses this all the time, but there are a few questions that I don"t understand
1. Why use URLEncoder.encode (filename, "utf-8"); encode it in application/x-www-form-urlencoded MIME format? My entire web application environment is UTF-8, why should I use UTF-8 for coding?
2.application/x-www-form-urlencoded MIME format isn"t this the format that the client requests from the server? Why does the server respond in this format?
3. What kind of code can the browser parse? I see the use of new String (fileName1.getBytes ("UTF-8"), "ISO8859-1"); in Google, Firefox can also parse Chinese file names. Is there no way to tell the browser to decode according to a certain encoding?