简体   繁体   English

从JavaScript调用applet的方法

[英]Calling applet's method from JavaScript

I need to print some information via an applet. 我需要通过小程序打印一些信息。 My applet from signed qds-client.jar: 我的小程序来自签名的qds-client.jar:

public class PrintText extends Applet  implements Printable {

 private ClientAccount clientAccount;

 public ClientAccount getClientAccount() {
     return clientAccount;
 }

 public void setClientAccount (ClientAccount clientAccount) {
     this.clientAccount = clientAccount;
 }

 public void setClientAccountFromJSON(String json) {
     this.clientAccount = toClientAccountFromJSON(json);
     System.out.println("------------------------------SetClient");
 }

 public int print(Graphics g, PageFormat format, int page) throws
         ...
 }

 public void printText() throws PrinterException {
     ...
 }

 private String getTextToPrint(ClientAccount clientAccount) throws PrinterException {
     ...
 }

 private ClientAccount toClientAccountFromJSON(String json) {
     return JsonUtils.fromJson(ClientAccount.class, json);
 }

 public void startPrint () {
     System.out.println("------------------------------------------Start");
 }
}

Accordinng JNLP: 根据JNLP:

<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.5+" codebase="http://localhost:10099/partials/" href="print.jnlp">
    <information>
       ....
    </information>

<resources>
    <jar href="/partials/qds-client.jar"/>
    <jar href="/partials/core-3.2.1.jar"/>
    <jar href="/partials/gson-2.3.1.jar"/>
</resources>

<applet-desc name="printText" main-class="com.qdsrest.utils.printer.PrintText" width="500" height="200"></applet-desc>

<update check="background"/>
<security>
    <all-permissions/>
</security>

and HTML tag: 和HTML标签:

<applet name="printApplet" jnlp_href="/partials/print.jnlp" width="10" height="10">
<param name="permissions" value="all-permissions"/>
</applet>

When I call applet's method from js file like this: 当我从js文件中调用applet的方法时,如下所示:

document.printApplet.setClientAccountFromJSON({/not empty/});

I get 我懂了

Error: Error calling method on NPObject!

in Mozilla and 在Mozilla和

basic: JNLP2ClassLoader.findClass: com.google.gson.internal.bind.CollectionTypeAdapterFactory: try again ..
basic: JNLP2ClassLoader.findClass: com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter: try again ..
basic: JNLP2ClassLoader.findClass: com.google.gson.internal.bind.MapTypeAdapterFactory: try again ..
basic: JNLP2ClassLoader.findClass: com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter: try again ..
basic: JNLP2ClassLoader.findClass: com.google.gson.internal.bind.JsonAdapterAnnotationTypeAdapterFactory: try again ..

in Java Console and method doesn't work. 在Java控制台中,方法无效。 Why I get "try again .."? 为什么我会“再试一次..”? What does it mean? 这是什么意思? Method toClientAccountFromJSON uses GSON lib gson-2.3.1.jar wich perfectly deserialize JSON object into Java object. 方法toClientAccountFromJSON使用GSON lib gson-2.3.1.jar,将JSON对象完全反序列化为Java对象。 What wrong things did I do? 我做了什么错事? Tell me, please, a right thinking way. 请告诉我,正确的思维方式。

I don't recall the current details, but long ago at the age of the first browser wars, there once was an attribute mayscript your applet needed in order to talk to javascript. 我不记得当前的细节,但是很久以前,在第一次浏览器大战的年代,曾经有一个属性mayscript您的applet才能与javascript对话。

Oh and parameter needs to be string: 哦,参数必须是字符串:

 setClientAccountFromJSON("somestring or stringvar");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM