Javascript到javaapplet的通信

Javascript到javaapplet的通信,java,javascript,applet,Java,Javascript,Applet,我正在尝试使用小程序中的setter方法,将HTML下拉列表中的选定值传递给小程序方法。但每次调用Javascript时,它都会显示“对象不支持此属性或方法”作为例外 我的javascript代码: function showSelected(value){ alert("the value given from"+value); var diseasename=value; alert(diseasename); document.decisiontreeapp

我正在尝试使用小程序中的setter方法,将HTML下拉列表中的选定值传递给小程序方法。但每次调用Javascript时,它都会显示“对象不支持此属性或方法”作为例外

我的javascript代码:

function showSelected(value){
    alert("the value given from"+value);
    var diseasename=value;
    alert(diseasename);
    document.decisiontreeapplet.setDieasename(diseasename);

    alert("i am after value set ");
}
我的小程序代码:

package com.vaannila.utility;


import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;


import prefuse.util.ui.JPrefuseApplet;

public class dynamicTreeApplet extends JPrefuseApplet {

    private static final long serialVersionUID = 1L;
    public static int i = 1;
    public String dieasenameencode;
    //System.out.println("asjdjkhcd"+dieasenameencode);
    public void init() {
        System.out.println("asjdjkhcd"+dieasenameencode);
        System.out.println("the value of i is " + i);
        URL url = null;
        //String ashu=this.getParameter("dieasenmae");
        //System.out.println("the value of the dieases is "+ashu);

        //Here dieasesname is important to make the page refresh happen 

        //String dencode = dieasenameencode.trim();
        try {
            //String dieasename = URLEncoder.encode(dencode, "UTF-8");
            // i want this piece of the code to be called 
            url = new URL("http://localhost:8080/docRuleToolProtocol/appletRefreshAction.do?dieasename="+dieasenameencode);
            URLConnection con = url.openConnection();
            con.setDoOutput(true);
            con.setDoInput(true);
            con.setUseCaches(false);
            InputStream ois = con.getInputStream();
            this.setContentPane(dynamicView.demo(ois, "name"));
            ois.close();

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (FileNotFoundException f) {
            f.printStackTrace();

        } catch (IOException io) {
            io.printStackTrace();
        }
        ++i;
    }

    public void setDieasename(String message){
        System.out.println("atleast i am here and call is made ");
        this.dieasenameencode=message;
        System.out.println("the final value of the dieasenmae"+dieasenameencode);

    }

}
我的appletdeployment代码:

<applet id="decisiontreeapplet" code="com.vaannila.utility.dynamicTreeApplet.class" archive="./appletjars/dynamictree.jar, ./appletjars/prefuse.jar" width ="1000" height="500" >    
</applet>

尝试使用param标记传递参数:

尝试将小程序标记中的id参数改为name


更改

document.decisiontreeapplet
…到

document.getElementById('decisiontreeapplet')
…而且它很可能会起作用

例如。 HTML

请同时考虑下一个简短的完整例子。请注意,上面显示的两个源中的行数比您的小程序短,并且我花了更长的时间准备源,以便检查我的答案。

我认为需要更多信息。

可能是@Nate的重复,看起来非常熟悉!OP请不要回复问题。嗨,andrew,即使现在它也不工作。每次我尝试在applet对象中调用setmethod时,它都会说对象不支持此方法。他们是否有任何调试方法。上面显示的示例在FF中对我有效。如果使用FF,请打开错误控制台(Ctrl+Shift+J)。这是一个缓存问题。它对我也有效:)非常感谢
document.getElementById('decisiontreeapplet')
<html>
<body>
<script type='text/javascript'>
function callApplet() {
    msg = document.getElementById('input').value;
    applet = document.getElementById('output');
    applet.setMessage(msg);
}
</script>
<input id='input' type='text' size=20 onchange='callApplet()'>
<br>
<applet
    id='output'
    code='CallApplet'
    width=120
    height=20>
</applet>
</body>
</html>
import javax.swing.*;

public class CallApplet extends JApplet {

    JTextField output;

    public void init() {
        output = new JTextField(20);
        add(output);
        validate();
    }

    public void setMessage(String message) {
        output.setText(message);
    }
}