如何在Web应用程序中运行小程序
我遇到了 在 Web 应用程序中运行小程序中所述的完全相同的问题。它为我的小程序抛出一个 ClassNotFoundException
。我尝试了那里的解决方案,但仍然没有运气。
这是我在 html 中嵌入 Applet 的代码:
<body>
<applet codebase="/DaaS/applet" archive="/DaaS/applet/firstApplet.jar" code="FirstApplet.class" width="300" height ="300"> </applet>
我有一个文件夹 DaaS/applet
,其中包含 firstApplet.jar,我的 index.html
位于 Daas/Webcontent
中。
I'm having the exact same problem stated in run applet in web application. It throws a ClassNotFoundException
for my applet. I tried the solution from there but still no luck.
Here is my code for embedding Applet in html:
<body>
<applet codebase="/DaaS/applet" archive="/DaaS/applet/firstApplet.jar" code="FirstApplet.class" width="300" height ="300"> </applet>
I've a folder DaaS/applet
which contains firstApplet.jar and my index.html
is in Daas/Webcontent
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
codebase
(和archive
)属性中的 URL 相对于当前请求 URL(您在浏览器地址栏中看到的 URL),而不是相对于磁盘文件系统服务器端。想象一下,您的index.html
页面位于某个子文件夹中,如下所示:中的 URL < code>codebase(和
archive
)属性以前导斜线/
开头,这使得它相对于域根目录而不是当前文件夹。因此网络浏览器将在以下 URL 中查找存档和 JAR这可能不是本身是正确的。您需要确保
codebase
(和archive
)URL 指向相对于当前请求URL 的正确URL。根据到目前为止给出的信息,/DaaS
文件夹基本上与index.html
位于同一父级中,因此应该这样做:(请注意,我简化了
archive
属性,无论如何,它将相对于codebase
进行解析)这样浏览器将从以下位置加载 JAR:
The URL in the
codebase
(andarchive
) attribute is relative to the current request URL (the one as you see in browser address bar), not to the disk file system in the server side. Imagine that you've theindex.html
page in some subfolder like so:The URL as you have in the
codebase
(andarchive
) attribute starts with a leading slash/
which makes it relative to the domain root instead of the current folder. So the webbrowser will look for the archive and the JAR in the following URLThis may not be correct per se. You need to make sure that the
codebase
(andarchive
) URL points to the right URL relative to the current request URL. Based on the information given so far, the/DaaS
folder is basically in the same parent asindex.html
, so this should do:(note that I simplified the
archive
attribute, it will be resolved relative tocodebase
anyway)This way the browser will load the JAR from: