The problem seems is a header encoding proglem. Tomcat 4.1.29 always return headers encoded in UTF8 irrespective of content type and any other settings. This casued browser(MSIE) cannot download file with correct non-ISO characters filename. There is no such problem found in 4.0.6 which outputs the filename in headers with ISO encoding. Have tried charset=Big5, ISO8859-1, ..., all failed. Example: // filename obtained from file system in ISO format and convert to correct xxx encoding filename=new String(filename.getBytes("ISO8859-1"), "xxx"); response.setContentType("application/x-download;charset=xxx"); response.setHeader("Content-Disposition", "filename="+filename); ServletOutputStream out = response.getOutputStream(); // ... read the file from disk and write to user out.close();
There's nothing in any spec which states the encoding that must be used for headers. content-type specifies the entity body encoding only.
This spec grey area caused Tomcat cannot support non-ISO filename file download since 4.1.2x. I think it needs to define clearly somewhere or better to leave header encoding as ISO8859-1 as in 4.0.x version rather than UTF8 that most browsers, e.g. IE, do not understand.
Just further found it is a "bug" in Coyote/JK2 AJP 1.3 connector which comes with Tomcat 4.1.2x. I have tested the old org.apache.ajp.tomcat4.Ajp13Connector with Tocmat 4.1.2x and found everything backs to normal, i.e. Headers are encoded in ISO8859-1 rather than UTF8
I agree with Remy on this. However, I'll have to look into why mod_jk is encoding headers at all. It is unlikely to be fixed in mod_jk, but hopefully mod_jk2 will support sending bytes in the headers.
After searching the sources, I found that in around line 333 of JkCoyoteHandler.java specifies the use of UTF8. Is it the problem area which always encode the headers in UTF8? private void appendHead(org.apache.coyote.Response res) throws IOException { .... C2BConverter c2b=(C2BConverter)res.getNote( utfC2bNote ); if( c2b==null ) { c2b=new C2BConverter( "UTF8" ); <====== the problem line? res.setNote( utfC2bNote, c2b ); } ....
*** This bug has been marked as a duplicate of 27796 ***