如何在Web应用程序中运行小程序

发布于 2025-01-02 04:47:41 字数 549 浏览 2 评论 0原文

我遇到了 在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

菊凝晚露 2025-01-09 04:47:41

codebase(和 archive)属性中的 URL 相对于当前请求 URL(您在浏览器地址栏中看到的 URL),而不是相对于磁盘文件系统服务器端。想象一下,您的 index.html 页面位于某个子文件夹中,如下所示:

http://localhost:8080/somecontext/index.html

中的 URL < code>codebase(和 archive)属性以前导斜线 / 开头,这使得它相对于域根目录而不是当前文件夹。因此网络浏览器将在以下 URL 中查找存档和 JAR

http://localhost:8080/DaaS/applet/firstApplet.jar< /p>

这可能不是本身是正确的。您需要确保codebase(和archive)URL 指向相对于当前请求URL 的正确URL。根据到目前为止给出的信息,/DaaS 文件夹基本上与 index.html 位于同一父级中,因此应该这样做:

<applet codebase="DaaS/applet" archive="firstApplet.jar" ... />

(请注意,我简化了archive 属性,无论如何,它将相对于 codebase 进行解析)

这样浏览器将从以下位置加载 JAR:

http://localhost:8080/somecontext/DaaS/applet/firstApplet.jar< /a>


The URL in the codebase (and archive) 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 the index.html page in some subfolder like so:

http://localhost:8080/somecontext/index.html

The URL as you have in the codebase (and archive) 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 URL

http://localhost:8080/DaaS/applet/firstApplet.jar

This may not be correct per se. You need to make sure that the codebase (and archive) 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 as index.html, so this should do:

<applet codebase="DaaS/applet" archive="firstApplet.jar" ... />

(note that I simplified the archive attribute, it will be resolved relative to codebase anyway)

This way the browser will load the JAR from:

http://localhost:8080/somecontext/DaaS/applet/firstApplet.jar

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文