[英]Embedding Java Applet in web page
I've built a java applet and am trying to embed it into an HTML file on my server. 我已经构建了一个Java小程序,并试图将其嵌入到服务器上的HTML文件中。 When I access the page, the applet tries to load but then crashes with a
ClassNotFoundException
on .applet.BookingApplet.class
(which is the name of the applet, where applet
is the name of the package the applet is in.) 当我访问该页面时,该applet尝试加载,但随后在
.applet.BookingApplet.class
上发生ClassNotFoundException
崩溃(这是applet
的名称,其中applet
是该applet所在的包的名称。)
<body>
<script src ="http://java.com/js/deployJava.js"></script>
<script>
var attributes = {
codebase: '/webapp/HelpSessions.jar',
code: '/webapp/HelpSessions.jar/applet/BookingApplet.class',
archive: '/lib/javax.persistence.jar, /lib/javax.validation-1.0.0.GA.jar, /lib/joda-time-2.1.jar, /lib/mail.jar, /lib/mysql-connector-java-5.1.23-bin.jar',
width: 800,
height: 600
};
var version = "1.6"
deployJava.runApplet(attributes, version);
</script>
</body>
This is the first time I've tried to do anything like this, so I'm sure this is just a syntactical error with the way I'm referring to the class files in the HTML. 这是我第一次尝试做这样的事情,所以我确定这只是我在HTML中引用类文件的方式上的语法错误。 I can post any other code if needed, but I don't think its relevant because the applet runs fine in AppletViewer.
如果需要,我可以发布任何其他代码,但是我认为它无关紧要,因为applet在AppletViewer中运行良好。
I'm not going to sleep tonight till I get this thing running... 直到我让这个东西运行起来,我今晚才睡觉。
EDIT: To simplify things, I tried moving everything into one folder so I wouldn't have to deal with the codebase. 编辑:为简化起见,我尝试将所有内容移动到一个文件夹中,因此我不必处理代码库。 Here's what it looks like now:
这是现在的样子:
<html>
<head>
<title>Schedule a Help Session</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<script src ="http://java.com/js/deployJava.js"></script>
<script>
var attributes = {
code: '/applet/BookingApplet.class',
archive: '/lib/javax.persistence.jar, /lib/javax.validation-1.0.0.GA.jar, /lib/joda-time-2.1.jar, /lib/mail.jar, /lib/mysql-connector-java-5.1.23-bin.jar',
width: 800,
height: 600
};
var version = "1.6"
deployJava.runApplet(attributes, version);
</script>
</body>
and I'm getting the same ClassNotFoundException. 和我得到相同的ClassNotFoundException。 Also, I can see an InterruptedException in the details on the java console, but it doesn't tell me where (if anywhere) in my code the exception is being caused.
另外,我可以在Java控制台的详细信息中看到InterruptedException,但是它没有告诉我在代码中的什么地方(如果有的话)引起了异常。
Change the code
attribute to be "applet/BookingApplet.class". 将
code
属性更改为“ applet / BookingApplet.class”。 Currently you are using "/applet/BookingApplet.class". 当前,您正在使用“ /applet/BookingApplet.class”。
When Java reads a URL, it converts any '/':s to '.':s. Java读取URL时,会将任何'/':s转换为'。':s。 That will make the URL "/applet/BookingApplet.class" ".applet.BookingApplet.class".
这将使URL“ /applet/BookingApplet.class”“ .applet.BookingApplet.class”。 "applet/BookingApplet.class" will become "applet.BookingApplet.class", which is the correct one.
“ applet / BookingApplet.class”将变为“ applet.BookingApplet.class”,这是正确的。
Just remember to set codebase
to point to the directory where the "applet" directory is located. 只要记住将
codebase
设置为指向“ applet”目录所在的目录即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.