Odd number of non-english characters get broken in windows-chrome
Asked Answered
T

4

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>
Tanked answered 21/3, 2013 at 2:32 Comment(2)
What is the charset of the page in which the applet appears? Is it ISO-2022-KR?Helicopter
It is UTF-8.<meta http-equiv="Content-Type" content="text/html; charset=utf-8" >Tanked
T
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"/>
Tanked answered 19/4, 2013 at 0:43 Comment(0)
L
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

Leshalesher answered 21/4, 2013 at 4:6 Comment(10)
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.Tanked
Changing the locale in windows control panel did work while file.encoding=UTF-8 didn't.Tanked
What is current the default encoding on the client machine? And what client JRE version is installed?Leshalesher
encoding is ms949 and the jre version is 1.7.0_17Tanked
have you tried to set encoding as I described before (see point B and C)? Or you want to use jnlp elements only?Leshalesher
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.Tanked
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;Leshalesher
The webpage is encoded UTF-8 and everything else. Below is the same issue. #16360453Tanked
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...Leshalesher
public class MainApplet extends JApplet implements JSInterface {// , Runnable { // configure static { System.setProperty("file.encoding", "UTF-8"); }Tanked
T
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.

Tanked answered 22/4, 2013 at 7:53 Comment(0)
F
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.

Freezer answered 24/4, 2013 at 10:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.