嵌入小程序在我的网站上不起作用

发布于 2024-08-14 22:17:31 字数 1358 浏览 7 评论 0原文

我正在尝试编写一个小程序并将其放入我的网站中。我记得很久以前就用 Borland 做过这件事,当时 1.4 是最新版本。它当然使用了小程序标签(我当前正在使用)并且没有任何问题。但无论如何,我将类文件放在 httpdocs/ 自己的目录下,然后在网页中使用了这段代码:

<小程序代码=“wsavatar/WSavatar”宽度=“425”高度=“150”> 您的浏览器不支持 applet 标签。

当我尝试加载页面时,会发生这种情况:

Java插件1.6.0_17 使用 JRE 版本 1.6.0_17-b04 Java HotSpot(TM) Client VM

java.lang.ClassFormatError: Incompatible magic value 1008813135 in class file   
  wsavatar/WSAvatar
  at java.lang.ClassLoader.defineClass1(Native Method)
  at java.lang.ClassLoader.defineClass(Unknown Source)
  at java.security.SecureClassLoader.defineClass(Unknown Source)
  at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
  at java.lang.ClassLoader.loadClass(Unknown Source)
  at java.lang.ClassLoader.loadClass(Unknown Source)
  at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
  at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
  at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
  at java.lang.Thread.run(Unknown Source)
Exception: java.lang.ClassFormatError: Incompatible magic value 1008813135
in class file wsavatar/WSAvatar

我尝试制作一个快速本地 html 文件来使用相同的小程序代码加载小程序,并且它有效。我在网上查了一下,听到了与此错误有关的各种信息,但我发现似乎没有什么可以缓解它。有什么想法吗?

I'm trying to code an applet and put it in my website. I remember doing this a long time ago using Borland back when 1.4 was the latest version. It of course used the applet tag (which I'm using currently) and it had no issues. But anyways, I put the class files in httpdocs/ under its own directory, and then used this code in the web page:


<applet code="wsavatar/WSAvatar" width="425" height="150>
Your browser does not support the applet tag.
</applet>

And when I try to load the page, this happens:


Java Plug-in 1.6.0_17
Using JRE version 1.6.0_17-b04 Java HotSpot(TM) Client VM

java.lang.ClassFormatError: Incompatible magic value 1008813135 in class file   
  wsavatar/WSAvatar
  at java.lang.ClassLoader.defineClass1(Native Method)
  at java.lang.ClassLoader.defineClass(Unknown Source)
  at java.security.SecureClassLoader.defineClass(Unknown Source)
  at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
  at java.lang.ClassLoader.loadClass(Unknown Source)
  at java.lang.ClassLoader.loadClass(Unknown Source)
  at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
  at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
  at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
  at java.lang.Thread.run(Unknown Source)
Exception: java.lang.ClassFormatError: Incompatible magic value 1008813135
in class file wsavatar/WSAvatar

I have tried making a quick local html file to load the applet using the same applet code and it worked. I have looked around online and have heard various things pertaining to this error, but nothing seems to alleviate it, that I've found. Any ideas?

Ben

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

扎心 2024-08-21 22:17:31

幻数是类文件开头的一个四字节值 (0xCAFEBABE),它将其标记为类文件而不是任何其他类型的数据。

那么什么类型的文件有幻数1008813135呢?在十六进制中,字节为 0x3C、0x21、0x44、0x4F。在常见拉丁编码中解释为字符数据的是“”。可能继续为“”。我们这里有一个 HTML 文件。这是可能是由损坏的服务器返回的错误页面,仅在 HTTP 响应中显示非错误成功代码。

看看实际提供的内容,Web 浏览器可能会显示该页面,值得学习使用 telnet(或nc) 并手动输入 HTTP 响应 还有各种用于检查 HTTP 流量的实用程序。

The magic number is a four byte value (0xCAFEBABE) at the start of the class file that marks it as a class file rather than any other kind of data.

So what type of file has magic number 1008813135? In hex that becomes that bytes 0x3C, 0x21, 0x44, 0x4F. Interpreted as character data in common Latin encodings is "<!DO. Probably continuing as "<!DOCTYPE". What we have here is an HTML file. This is probably an error page returned by a broken server only with a non-error success code in the HTTP response.

Have a look at what is actually being served. A web browser will probably show the page. It is worth learning to use telnet (or nc) and type in the HTTP response by hand. There are also various utilities for inspecting HTTP traffic.

南薇 2024-08-21 22:17:31

问题似乎出在您的网站上,而不是您的代码中。通过谷歌搜索,该错误似乎是 OpenCMS 等系统最常报告的(特别是对于端口 8080 上的 URL)。

因此,我想象正在发生的情况是浏览器加载小程序的调用实际上失败了,但返回的是数据而不是 404/500 错误。 Java VM 尝试将返回的错误页面解释为类文件,并且非常正确地抱怨它毕竟不是有效的类文件。 (这种情况经常发生在重定向到主页而不是向用户返回实际 HTTP 错误的内容管理系统中。)

要进行测试,请尝试手动键入小程序的 URL(不是它所在的页面,而是小程序本身) )在浏览器中查看服务器返回的内容。

The problem appears to be in your website, not your code. Googling around, the error seems to be most frequently reported with systems such as OpenCMS (especially for URLs that are on port 8080).

So, what I imagine is happening is that the browser's call to load the applet is actually failing, but is returning data rather than a 404/500 error. The Java VM is attempting to interpret the returned error page as if it was a class file, and quite correctly complaining that it doesn't seem to be a valid class file after all. (This happens quite often with content management systems that redirect to the home page rather than return an actual HTTP error to the user.)

To test, try manually typing the URL to the applet (not the page it is hosted in, the applet itself) in your browser and see what the server returns.

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