I’m using a java applet to browse files/folders on a remote server (ftp/cifs).
The problem is that, if a folder on the remote server is named in non-ascii characters(say Japanese or Chinese language), the applet fails to launch.
I’ve traced back the problem which seems to be arising from incorrect parsing of the non-ascii string in the server response. Following is a snippet of the xml response from the server.
<?xml version="1.0" encoding="utf-8" ?><a:multistatus xmlns:b="urn:uuid:/" xmlns:c="xml:" xmlns:a="DAV:">
<a:response><a:href>https://xx.xx.xx.xx/folder/äèä¸?能æ£å¸¸å·¥ä½œ</a:href><a:propstat><a:status>HTTP/1.1 200 OK</a:status>
The charset encoding from server is requested to be utf-8 as above. The garbage looking string is the remote webfolder I’m trying to view using the applet, the folder is actually named 不能正常工作. Since the two are not equivalent (actual folder name and the one in the xml), java xml parsing throws an error while trying to launch the applet. Please suggest what could be done to fix this. Also I’m not using the SAX parser, I’m using the XML parser and then create a DOM object
The XML you have posted seems to contain the garbage characters. I mean that those unicode characters have been mangled while creation itself. So the first thing to check should be to make sure that you use right variant of APIs which takes charset as a parameter and use UTF-8 as the parameter in those places.On the server as well as the client se just double check the APIs. For example if you are creating InputStreamReader anywhere then make sure that you are using InputStreamReader(InputStream in, Charset cs) etc.