F
Fred Grafe
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
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