Today is the first day of work, I have to stay in my home because I want to get teeth. It is very enjoyable, but I really miss the 25 degrees of spring in the Shenzhen office.
I woke up by my colleague in the morning, the first day, I have a problem. Customers are the only standard for inspection projects. Based on the company's philosophy, I have to sleep, but also to get a very spirit to get it.
The problem is as follows: The attachment of the Chinese file name in the customer's forum system cannot be downloaded. My colleagues used their IE6 to test, and they did not download. When I got to the customer's system, I found that the file name of the attachment was quite long, almost 30 words. But my IE can be downloaded, but the file name head is truncated.
Regarding the problem of Chinese file download, online consultation and answering has been a lot, I originally handled the code code as follows:
Response.setHeader ("Content-Disposition", "Attachment; FileName =" java.net.urlencoder.Encode (FileName, "UTF-8"));
There is this sentence in the download program, usually in the download prompt box of IE6, the name of the file correctly, whether it is Simplified Chinese, or Japanese. However, the Chinese file name that did not have a long test of the file name. Now, after careful testing, you can't download as long as you have more than 17 words. After a good Google and repeated test, it finally had a systematic understanding of this issue, which is listed as follows:
I. Through my original way, I first use Urlencoder to encode. When Chinese text exceeds 17, IE6 cannot download files. This is the BUG of IE, see Microsoft's knowledge base articles
KB816868. The reason may be because IE is in processing the response header, the length of the Header is limited to about 150 bytes. And a Chinese character encodes a UTF-8 is 9 bytes, then 17 characters are 153 bytes, so they will report. Microsoft provides a patch, you can
Here download. This patch needs to install IE6 SP1 first. Because I usually fight patch, my IE6 version number is 6.0.2800.1106.xpsp2_xxxxx. So I may have already installed patches so that I can download, but still appear in the phenomenon truncated. Microsoft lets we wait for the release of IE next service pack. I also visited the Internet today, forced Firefox's pressure, IE7 may be released in the year. In addition, Firefox does not support this way, the encoded% xx% XX is displayed directly as a file name.
I'm trying to encode the file name using JavaMail's mimeutility.encode () method, that is, encoded into =? GB2312? B? Xxxxxxxx? = Such form, and from
The corresponding standard support is found in RFC1522. But unfortunate, IE6 does not support this standard. I tried it, Firefox is supported.
III. Press the solution provided by many people: encoding the file name into ISO8859-1 seems to be a valid solution, the code is as follows:
Response.setHeader ("Content-Disposition", "Attachment; FileName =" New String (Filename.GetBytes ("GB2312"), "ISO8859-1");
In the case of ensuring that the attachment file name is the simplified Chinese word, then this approach is really effective, and it is not necessary to upgrade IE one by one. If the Taiwan compatriots are used, the GB2312 is changed to BIG5. But the current system usually has added international support, and UTF-8 is commonly used. If there are simplified Chinese characters in the file name, there are traditional Chinese, and there are Japanese. So garbled. In addition, Firefox (V1.0-EN) download is also garbled on my computer. Formount, I combined with one, three ways, the code snippet is as follows:
String filename = urlencoder.encode (atta.getfilename (), "UTF-8");
/ *
* See
http://support.microsoft.com/default.aspx?kbid=816868
* /
IF (filename.length ()> 150) {
String guesscharset = xxxx / * derived possible coding according to Request's Locale, the Chinese operating system is usually GB2312 * /
FileName = new string (atta.getfilename (). getBytes (Guesscharset), "ISO8859-1");
}
Response.setHeader ("Content-Disposition", "Attachment; FileName =" FileName);
It is not considered that Firefox is because it does not seem to have effectively invading IE's corporate user market. It is often scheduled to affect customer payments, not compatibility.