Using servlet to dowload file with CJK filename

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top