从 Java 脚本调用 Applet 函数时出现问题
每次我从 Java 脚本调用小程序的函数时,它都会抛出未定义的异常。 我的谷歌搜索根本没有帮助我。
这是我现在托管的网站的链接: 主机站点
是我嵌入 Applet 的 html:
<object type="application/x-java-applet"
id="ClientApp" name="ClientApp"
archive="Cal.jar"
width="100" height="100">
<param name="code" value="Calendar_Algorithm" />
<param name="mayscript" value="true" />
</object>
这 我的java脚本代码:
function test(){
document.writeln("<p> "+"Test"+" </p>");
try{
var s=document.ClientApp.getGreeting();
document.writeln("<p> First: "+s+" </p>");
}catch(err){
document.writeln("<p>Error Caught 1: "+err.description+"</p>");
}
try{
var s=document.getElementById('ClientApp').getGreeting();
document.writeln("<p> Second: "+s+" </p>");
}catch(err){
document.writeln("<p>Error Caught 2: "+err.description+"</p>");
}
document.close();
}
我知道它会加载小程序,因为我可以看到gui,如果它有帮助的话,这里是我的init函数,
public void init() {
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
JLabel lbl = new JLabel(getGreeting());
add(lbl);
}
});
} catch (Exception e) {
System.err.println("createGUI didn't complete successfully");
}
}
这里还有我的完整代码的链接代码
我感觉错误非常明显,但我就是看不到它。
任何帮助都会很棒!
聚苯乙烯 Applet 类文件现在位于已签名的 jar 文件中。
另外,这将被放置在 tomcat 服务器的 webapps 文件夹中,但我当前将其作为本地文件访问。
Every time I call a function of my applet from my Java Script, it throws an undefined exception.
And my googling hasn't helped me at all.
here is a link to the site I am am hosting it on right now:
Host Site
Here is my html for the embedding the Applet:
<object type="application/x-java-applet"
id="ClientApp" name="ClientApp"
archive="Cal.jar"
width="100" height="100">
<param name="code" value="Calendar_Algorithm" />
<param name="mayscript" value="true" />
</object>
And here is my java script code:
function test(){
document.writeln("<p> "+"Test"+" </p>");
try{
var s=document.ClientApp.getGreeting();
document.writeln("<p> First: "+s+" </p>");
}catch(err){
document.writeln("<p>Error Caught 1: "+err.description+"</p>");
}
try{
var s=document.getElementById('ClientApp').getGreeting();
document.writeln("<p> Second: "+s+" </p>");
}catch(err){
document.writeln("<p>Error Caught 2: "+err.description+"</p>");
}
document.close();
}
I know it loads the applet because I can see the gui, and if it helps here is my init function
public void init() {
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
JLabel lbl = new JLabel(getGreeting());
add(lbl);
}
});
} catch (Exception e) {
System.err.println("createGUI didn't complete successfully");
}
}
here is a link to my full code as well Code
I got a feeling that the error is incredibly obvious, but I just can not see it.
Any help would be great!
P.S.
The Applet class files are now in a signed jar file.
Also This will be placed in the webapps folder of a tomcat server, but I am currently accessing it as a local file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自 http://www.w3.org/TR/html401/ struct/objects.html#h-13.4,关于对象属性:
“该属性命名包含小程序状态的序列化表示的资源。”
我预测这不是你想要的。
此外,如果您使用的是 firefox mac,则需要(JS-2-Java 交互)LiveConnect 的 mayscript 参数才能工作。
一种有效的部署小程序的方法:
如果您没有启用 Java 控制台,那么您绝对应该这样做。它在 Java 控制面板高级设置下启用。
顺便说一句,在 Chrome Linux 中它可以工作!在 Firefox Linux 中则不然。 Firefox 不喜欢同时指定对象和代码参数并且类名不同。
LiveConnect 存在缺陷,尤其是在 Mac 上。有关概述,请查看: applets-missing-information- about-liveconnect-and-deployment 基本上,您需要知道使用 LiveConnect 的哪些部分以及不使用哪些部分。
From http://www.w3.org/TR/html401/struct/objects.html#h-13.4, about the object attribute:
"This attribute names a resource containing a serialized representation of an applet's state."
I predict this is not what you intended.
In addition, if you're on firefox mac you need the mayscript param for (JS-2-Java interaction) LiveConnect to work.
A way to deploy applets that works:
If you don't have the Java console enabled you should definitely do so. It's enabled under the Java Control Panel advanced settings.
By the way, in Chrome Linux it works! In Firefox Linux it doesn't. Firefox doesn't like that both object and code param is specified and that the class names are different.
LiveConnect is buggy, especially on the mac. For an overview have a look at: applets-missing-information-about-liveconnect-and-deployment Basically you need to know what parts of LiveConnect to use and which not to.