japanese download filename 2004-01-08 - By David La France
Back Hello,
I've got a servlet that allows users to download files. I'm specifying the filename using the Content-Disposition header, and the charset using the Content-Type header. It all works lovely when the filename is English - but not with Japanese.
I got the following to work with the latest version of IE:
encodeFileName = URLEncoder.encode(fileName, "UTF-8 (See http://UTF-8.ora-code.com)"); response.setContentType("application/octet-stream"); // ie doesn't seem to need the charset if it's utf-8 (See http://utf-8.ora-code.com) response.setHeader("Content-Disposition", "attachment; filename=\"" + encodeFileName + "\"");
This, however, does not work with Netscape, nor does it work with older versions of IE (the name displays as escaped unicode). I need to support NE and IE (recent versions) on both Windows and Mac.
I played around with the headers for Netscape and tried everything I could think of, to no avail. I then used a packet sniffer to checkout the headers from a different application (PHP based) that works properly with Netscape - but even after I managed to get the headers for Content-Type AND Content-Disposition to match, it still didn't work (the action name shows up instead of the japanese file name).
Here are the settings I used to get the headers to match - the file name encoding matches byte for byte with the PHP app: encodeFileName = new String(fileName.getBytes("Shift_JIS"), "ISO-8859 (See http://ISO-8859.ora-code.com)-1"); response.setContentType("application/octet-stream; charset=Shift_JIS"); response.setHeader("Content-Disposition", "filename=" + encodeFileName);
for a file name PC$B4IM}(B.xls I get a filename=PC\212\307\227\235.xls in the header, which looks good to me.
Here are the (relevant) headers from the PHP app, which works fine (it's closed source, so no luck there): Content-Disposition: filename=PC\212\307\227\235.xls\r\n Content-Type: application/octet-stream; charset=Shift_JIS\r\n
I'm at a total loss. I've tried every charset, leaving OUT the charset, surrounding the filename in quotes, standing on my head... I stumbled across this tomcat bug (http://nagoya.apache.org/bugzilla/show_bug.cgi?id=24380) but the header encoding appears to be coming out ok. I tried tomcat 4.0.6 for the hell of it but that, of course, did not work either.
Is it possible that NS is ignoring the specified charset, and trying to get it from the data stream? If the headers are a match, what else could be happening? Are there other headers besides Content-Type and Content-Disposition that I should be worrying about?
One (slightly) strange thing is that my packet sniffer seems to automatically recognize the PHP app's packets at HTTP, but not the servlet app's packets (have to click the "decode as html" button).
Any help, ideas, suggestions, or prayers would be most welcome.
Thanks in advance, Dave
-- -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -- ADiRECT Corporation $B%"%G%#%l%/%H3t<02q<R!!!!!!!!!!!Z5l<RL>!'%(%L%T!<%7!<%7%9%F%`%I%C%H%3%`![(B ITS$B3+H/K\It!!(B David La France d.lafrance at adirect.jp $B")(B103-0001$B!!El5~ETCf1{6hF|K\66>.EAGOD.(B12$BHV(B8$B9f!!(B TEL $B!'(B03-5651-5700 $B!!(BFAX$B!'(B03-5651-5566 URL http://www.adirect.jp
--PR-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------ $B!zJ*N.Hq:o8:$r$*9M$($J$i!V%"%G%#%l%/%H(B e3PL $B%*%Z%l!<%7%g%s%;%s%?!<!W$X $4AjCL(B $B$/$@$5$$(B http://www.adirect.jp/logistics $B!z1?DB!&5wN%7W;;$,B.$$!"4JC1!*!VEE;RA49q2_J*<+F0<V1D6H%-%mDx?^!W!!9%I>H/GdCf (B $B!*(B http://www.adirect.jp/kilotei
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------ To unsubscribe, e-mail: tomcat-user-unsubscribe@(protected) For additional commands, e-mail: tomcat-user-help@(protected)
|
|