An odd number of non-English characters are broken into chrome windows.

I developed a jnlp applet that outputs user input.

When I put an odd number of non-English characters (like Chinese), the chrome browser prints the last character as a question mark.

input: 가 output: 가

I checked in the java console that the character is correct.

This should be a mistake in communicating the applet with the Chrome browser.

IE prints correctly.

I can solve the problem by adding a space to the applet and deleting it in a java script.

Does anyone have a clue to this problem?

The codes are as follows.

*MainApplet.Java* public class MainApplet extends JApplet implements JSInterface{//, Runnable { public int stringOut(String sData) { OutData = sData; return 0; } } *js File* function TSToolkitRealWrapper () { var OutData; var OutDataNum; } var TSToolkit = new TSToolkitRealWrapper(); var attributes = { id:'TSToolkitReal',code:'com.multibrowser.test.MainApplet', width:100, height:100} ; var parameters = {jnlp_href: getContextPath() + '/download/pkitoolkit.jnlp', separate_jvm:true, classloader_cache:false} ; TSToolkitRealWrapper.prototype.stringOut=function(str) { var nRet = TSToolkitReal.stringOut(str) ; this.OutData= TSToolkitReal.OutData; return nRet; } *HTML* <SCRIPT language=javascript> <!-- function StringOut(form) { var data = form.data.value; var nRet = 0; var base64Data; nRet = TSToolkit.stringOut(data); if (nRet > 0) { alert(nRet + " : " + TSToolkit.GetErrorMessage()); } else { form.data1.value = TSToolkit.OutData; } } --> </SCRIPT> *jnlp* <?xml version="1.0" encoding="UTF-8"?> <jnlp href="cmp.jnlp"> <information> <title>MultiBrowser</title> </information> <security> <all-permissions/> </security> <resources> <j2se version="1.6+" /> <jar href="MultiBrowser.jar"/> </resources> <applet-desc height="200" main-class="com.multibrowser.test.MainApplet" name="MainApplet" width="200"/> </jnlp> 
+6
source share
4 answers

I asked in several web browser forums, but there are no answers yet.

The difference between Windows and Linux is the value of file.encoding. Windows (ms959) and Linux (UTF-8).

I cannot figure out how to set the value of file.encoding.

Below nothing happened. When I press 's' in the java console, it still prints the .encoding = MS949 file.

 <?xml version="1.0" encoding="UTF-8"?> <jnlp href="pkitoolkit.jnlp"> <security> <all-permissions/> </security> <resources> <j2se version="1.6+" java-vm-args="-Dfile.encoding=UTF-8" /> <property name="file.encoding" value="UTF-8"/> 
+2
source

IE prints correctly

Umm ...

You give less details ... anyway , if you can enter Chinese characters in your browser, but getting garbage at the output of the applet means that your Internet browser supports Chinese, but your applet does not ;

I assume that you should look closer to the JRE encoding settings for client machines, because by default this may not support Chinese encoding, so maybe your applet should have some manual localization control ...

A. I can advise you to go deeper into the Locale user language settings

I suspect file.encoding is a problem if you look at my own answers below. I could not find how to set the encoding though

B. You can use static code like this to set a property (put it at the very beginning of your applet code)

 static { System.setProperty("file.encoding", "UTF-8"); } 

FROM.

When I put an odd number of non-English characters (ex: Chinese), the chrome browser prints the last character in the question mark.

and...

the encoding is ms949, and the jre version is 1.7.0_17

... the concept is rather strange: S If you have chrome with support for Korean letters, and this is ms949 as the default encoding for your computer, but at the same time you want your applet to support utf-8 and output Korean characters correctly from JS back to your ms494 secure web page. I suspect you are encountering some kind of incompatible% P coding

So first of all, I recommend making your utf-8 applet support web page instead of the standard ms494, because I assume that the applet and its cp (s) web page may be incompatible: S


Report if this helped

+2
source

Changing the locale in the Windows Control Panel to English did work, but file.encoding = UTF-8 didn't. I am still working on why this is happening.

+2
source

I had the same problem about 2 months ago in J2ME, I solve the problem using the String.trim () method, if your text does not have a space at the end, you can try this.

+2
source

All Articles