6

我开发了打印出用户输入的 jnlp 小程序。

当我输入奇数个非英文字符(例如:中文)时,chrome 浏览器会打印出最后一个字符作为问号。

输入:가 输出:가��

我在 java 控制台上检查了字符是否正确。

一定是applet与chrome浏览器通信的bug。

IE 打印正确。

我可以通过在小程序上附加空格并在 java 脚本上将其删除来解决此问题。

有人对这个问题有任何线索吗?

代码如下。

*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>
4

4 回答 4

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

于 2013-04-21T04:06:42.493 回答
2

大约 2 个月前我在 J2ME 遇到了同样的问题,我使用 String.trim() 方法解决了问题,如果你的文本最后没有空格,你可以试试。

于 2013-04-24T10:46:42.237 回答
2

我在几个网络浏览器论坛上问过,但还没有答案。

Windows 和 Linux 之间的区别在于 file.encoding 值。Windows(ms959) 和 Linux(UTF-8)。

我不知道如何设置 file.encoding 值。

下面没有工作。当我在 java 控制台中按“s”时,它仍然打印 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"/>
于 2013-04-19T00:43:52.767 回答
2

将 Windows 控制面板中的语言环境更改为英语确实有效,而 file.encoding=UTF-8 没有。我仍在研究为什么会发生这种情况。

于 2013-04-22T07:53:08.267 回答