开发者

Unicode/Japanese characters in a Java applet

开发者 https://www.devze.com 2022-12-10 07:39 出处:网络
I\'m writing an applet that\'s supposed to show both English and Japanese (unicode) characters on a JLabel. The Japanese character开发者_如何学编程s show up fine when I run the applet on my system, bu

I'm writing an applet that's supposed to show both English and Japanese (unicode) characters on a JLabel. The Japanese character开发者_如何学编程s show up fine when I run the applet on my system, but all I get is mojibake when I run it from the web page. The page can display Japanese characters if they're hard-coded into the HTML, but not in the applet. I'm pretty sure I've seen this sort of thing working before. Is there anything I can do in the Java code to fix this?


My first guess would be that the servlet container is not sending back the right character set for your webapp resources. Have a look at the response in an HTTP sniffer to see what character set is included - if the response says that the charset is e.g. CP-1252, then Japanese characters would not be decoded correctly.

You may be able to fix this in code by explicitly setting a Content-Type header with the right charset; but I'd argue it's more appropriate to fix the servlet container's config to return the correct character set for the relevant resources.


Well I'm not sure what was causing the problem, but I set EVERYTHING to read in and display out in UTF-8 and it seems to work now.

0

精彩评论

暂无评论...
验证码 换一张
取 消