Applet:如何将参数从Applet传递给html

时间:2015-01-30 09:53:09

标签: java html applet parameter-passing

我知道如何将参数从HTML传递到Applet,有人可以展示如何将参数从Applet传递到HTML吗?

1 个答案:

答案 0 :(得分:0)

请尝试以下操作:

小程序代码:

public class applet_test extends Applet {
    private InetAddress addr = null;
    public void init() {
        try {
            addr = InetAddress.getLocalHost();
        }
        catch (UnknownHostException e) {
            System.exit(0);
        }
    }
    public InetAddress getLHost() {
        return addr;
    }
}

HTML代码:

<html>
<body>
<APPLET CODE=applet_test.class Width=0 Height=0></APPLET>
<script type="text/javascript">

document.write(document.applets[0].getLHost());

</script>
</body>
</html>