简体   繁体   English

如何向 java 小程序添加新参数以从 javascript 调用另一个方法?

[英]How to add new parameters to a java applet to call another method from javascript?

I am using a java applet to call Web Services.我正在使用 java 小程序调用 Web 服务。 This java applet is embedded in a html web page like this:此 java 小程序嵌入在 html web 页面中,如下所示:

<object classid="java:TEST3.class"
                codebase="lib/"
                type="application/x-java-applet"
                width="5000" height="50"
                archive="sTest11.jar" name="TEST3" id="TEST3">
    <param name="TEST3" value="TEST3" />
    alt : <a href="TEST3.class">TEST3.class</a>
    <!-- Safari needs this -->
    <param name="JAVA_CODEBASE" value="lib" />
    <param name="BGCOLOR" value="000000" />
    <param name="TEXTCOLOR" value="FF0000" />
    <param name="TEXT" value="Test" />
    <param name="SPEED" value="250" />
    <param name="RANDOMCOLOR" value="1" />
    <param name="mayscript" value="yes"/>
    <param name="scriptable" value="true" />
</object>

So when the web page is opened, the applet starts.所以当web页面打开时,小程序启动。 I have a javascript file which calls the init() method to call a first web service.我有一个 javascript 文件,它调用 init() 方法来调用第一个 web 服务。 Then I retrieve datas, that I need to call a second web service.然后我检索数据,我需要调用第二个 web 服务。 That's why I need here to add parameters to my java applet.这就是为什么我需要在这里为我的 java 小程序添加参数。 If I use in javascript:如果我在 javascript 中使用:

document.getElementById('TEST3').innerHTML +='<param name="PARAM1" value="'+var1+'"/>';

and then接着

javascript:document.getElementById('TEST3').mymethod2();

it does not work.这没用。 The applet is not reloaded.小程序不会重新加载。 (but it works if I put manually a parameter before loading the whole page, so the problem is the reloading of the applet in order to take the new parameter). (但如果我在加载整个页面之前手动输入参数,它会起作用,所以问题是重新加载小程序以获取新参数)。 I tried to call the stop() method, then the destroy() one, then another init() and then the request I want but it does not work.我尝试调用 stop() 方法,然后调用 destroy() 方法,然后调用另一个 init(),然后调用我想要的请求,但它不起作用。

I manage to do my requests with different applets (with several innerHTML which create each one applet step by step), but it does not work exactly as I want, and I really would prefer use only one.我设法使用不同的小程序(使用几个 innerHTML 逐步创建每个小程序)来完成我的请求,但它并不能完全按照我的意愿工作,我真的更喜欢只使用一个。

If you have any idea, thank you very much for your help.如果您有任何想法,非常感谢您的帮助。

Try invoking your function like this instead:尝试像这样调用您的 function :

document.TEST3.mymethod2();

And see if that works.看看这是否有效。

EDIT编辑

Based off your comments I understand you were trying to pass additional startup parameters to the Applet on your page.根据您的评论,我了解到您正在尝试将其他启动参数传递给您页面上的小程序。 Which is of course not really possible (keyword startup :).这当然是不可能的(关键字启动:)。 With your first method you had this:用你的第一种方法,你有这个:

document.getElementById('TEST3').innerHTML +='<param name="PARAM1" value="'+var1+'"/>';

But your object tag (correctly) doesnt have any innerHTML .但是您的 object 标签(正确)没有任何innerHTML And params are not specified in the object tag body anyway so no matter what this will have no useful effect.无论如何,在 object 标签正文中都没有指定参数,所以无论如何这都没有任何用处。 Your second method had this:你的第二种方法是这样的:

javascript:document.getElementById('TEST3').mymethod2();

Which according to your comments works, but of course there is no data getting passed in so your Applet parameters do not change.根据您的评论,哪个有效,但当然没有数据传入,因此您的 Applet 参数不会更改。 What you do want to do is this:你想要做的是:

javascript:document.getElementById('TEST3').mymethod2(someparameter);

Of course, your method signature on the Applet should match!当然,您在 Applet 上的方法签名应该匹配!

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

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