Using servlet to dowload file with CJK filename
From: Fred Grafe (fred.grafe_at_compoze.com)
Date: 12/17/03
- Next message: Chris Smith: "Re: include uploaded by a customer html to jsp"
- Previous message: Vincent Cate: "Target VM Microsoft? or Java Lint to check for MS VM compatibility?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Chris Smith: "Re: include uploaded by a customer html to jsp"
- Previous message: Vincent Cate: "Target VM Microsoft? or Java Lint to check for MS VM compatibility?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|