Using servlet to dowload file with CJK filename

From: Fred Grafe (fred.grafe_at_compoze.com)
Date: 12/17/03


Date: 17 Dec 2003 11:55:12 -0800

If anyone can help me here, that would be great.

I have a servlet that is used to download files to the local machine
(via the browser). I've hit a snag where the filename contains CJK
characters. When the dialog appears to save/open the file, the
filename is not correct. For example, the filename ?CJK.txt would
appear as ýýýCJK.txt in the dialog(s).

Here is a code snippet

response.setContentType(data.getContentType() + "; charset=UTF-8");

System.out.println("DEBUG: name = " + info.getName());
System.out.println("DEBUG: name (bytes) = " +
StringUtility.bytesToHex(info.getName().getBytes()));
System.out.println("DEBUG: name (bytes utf-8) = " +
StringUtility.bytesToHex(info.getName().getBytes("utf-8")));

// Chinese characters still does not appear correctly, but
// it is getting closer.
response.setHeader("Content-Disposition",
"attachment; filename=\""
+ new String(info.getName().getBytes("UTF-8"), "ASCII")
+ "\";");

I know the string is UTF-8 encoded, below is the out of the println
DEBUG: name = ?CJK.txt
DEBUG: name (bytes) = 3F434A4B2E747874
DEBUG: name (bytes utf-8) = E4BD9C434A4B2E747874

Thanks
Fred



Relevant Pages

  • Using servlet to dowload file with CJK filename
    ... I have a servlet that is used to download files to the local machine ... I've hit a snag where the filename contains CJK ... DEBUG: name = 3F434A4B2E747874 ...
    (comp.lang.java.programmer)
  • Download by PUTTY?
    ... how can i download files by putty. ... Something like "get filename"? ... Thnx ...
    (comp.os.linux.networking)