6

I developed jnlp applet which prints out the user input.

When I put odd number of non-english characters(eg: chinese), chrome browser prints out the last character as question mark.

input : 가 output : 가��

I checked on java console that the character is correct.

It must be bug in communication of applet to chrome browser.

IE prints out correctly.

I can resolve the issue by appending white space on applet and remove it on java script.

Anyone has any clue on the issue?

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>
tompal18
  • 1,164
  • 2
  • 21
  • 39

4 Answers4

2

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

Difference between Windows and Linux is file.encoding value. Windows(ms959) and Linux(UTF-8).

I can't figure how to set the file.encoding value though.

Below didn't work. When I press 's' in java console, it still prints file.encoding=MS949.

<?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"/>
tompal18
  • 1,164
  • 2
  • 21
  • 39
2

IE prints out correctly

Emm...

You give less details... anyway if you can enter chinese characters in your browser but get some rubbish on applet output means that your internet broswer supports chinese but your applet doesn't;

I presume you should watch closer to your client machine JRE encoding settings because it maybe doesn't support chinese encoding by default so maybe your applet should have some manual localization control...

A. I can advise dig deeper into applet Locale user language settings...

I suspect that the file.encoding is the problem, if you look at my own answers below. I couldn't find how to set the encoding though

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

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

C.

When I put odd number of non-english characters(eg: chinese), chrome browser prints out the last character as question mark.

and...

encoding is ms949 and the jre version is 1.7.0_17

...the conception is pretty weird :S If you have your chrome with korean letters support and it is ms949 as your client machine default encoding but at the same time you want to make your applet support utf-8 and output korean characters correctly with JS back to your ms494 encoded web page I do suspect you do face some kind of incompatible encodings %P

So first, I do recommend to make your applet web page support utf-8 encoding instead of the default ms494 because I suppose the applet and its web page cp(s) might be incompatible :S


Report if that helped

user592704
  • 3,674
  • 11
  • 70
  • 107
  • I suspect that the file.encoding is the problem, if you look at my own answers below. I couldn't find how to set the encoding though. – tompal18 Apr 22 '13 at 02:42
  • Changing the locale in windows control panel did work while file.encoding=UTF-8 didn't. – tompal18 Apr 22 '13 at 07:49
  • What is current the default encoding on the client machine? And what client JRE version is installed? – user592704 Apr 22 '13 at 17:14
  • encoding is ms949 and the jre version is 1.7.0_17 – tompal18 Apr 23 '13 at 04:27
  • have you tried to set encoding as I described before (see point B and C)? Or you want to use jnlp elements only? – user592704 Apr 23 '13 at 16:56
  • I tried B and set UTF-8 on every html, jnlp, java control pannel and static block in java. But nothing worked. Only thing which worked is windows's Locale change. – tompal18 Jun 04 '13 at 08:02
  • As I was saying, the problem may be not in your applet only but in your Web page encoding... you have, somehow, make your web page and applet encoding(s) be identical to avoid mismatch; – user592704 Jun 04 '13 at 16:48
  • The webpage is encoded UTF-8 and everything else. Below is the same issue. http://stackoverflow.com/questions/16359953/why-does-my-unicode-string-get-corrupted-when-passed-from-java-applet-to-java-s – tompal18 Jun 05 '13 at 07:56
  • Have you placed the code (see point B) in static block? The static block must be at the very beginning of the class (above the usual fields decl-s lines) - the class which contains the applet init method? Show the applet with the static block snippet... – user592704 Jun 05 '13 at 16:24
  • public class MainApplet extends JApplet implements JSInterface {// , Runnable { // configure static { System.setProperty("file.encoding", "UTF-8"); } – tompal18 Jun 07 '13 at 00:20
2

Changing the locale in windows control panel to english did work while file.encoding=UTF-8 didn't. I am still working on why this happens.

tompal18
  • 1,164
  • 2
  • 21
  • 39
2

I had the same problem about 2 months ago at J2ME, I solve problem with using String.trim() method, if your text doesn't have white space at the end you could try that.

Utkan Ozyurek
  • 638
  • 7
  • 20