Applet 不会从 GlassFish 运行,魔法值不兼容。从 OS X Web 服务器运行良好
对于编程作业,我试图让 GlassFish 服务器提供客户端小程序来与服务器 servlet 对话。我一直坚持让 GlassFish 交付小程序。我一直在对此进行广泛的搜索,但没有找到任何可以解决该问题的东西 - 尽管我学到了很多东西。
我有一个编译为 tskApplet.class 的“hello world”小程序。
import java.applet.Applet;
import java.awt.*;
public class tskApplet extends Applet {
public void paint (Graphics g) {
g.drawString("Hello world! It's an applet!", 5, 25);
}
}
我有一个 html 页面,它使用以下小程序标签加载小程序:
<applet code = "tskApplet.class" width="300" height="300"></applet>
我尝试了(无济于事)各种变体,例如将 .class 文件放入 .jar 中,并在applet 标签,并使用 .jsp 页面等。
我正在使用 IntelliJ,如果我从 applet 运行/调试配置运行 tskApplet,它可以正常工作。我按照本指南使用 ImtelliJ 设置 GlassFish: http://wiki.jetbrains.net/intellij/Developing_applications_for_GlassFish_Server_in_IntelliJ_IDEA< /a>
如果我将完全相同的 .class 文件和 .html 文件从 GlassFish 服务器的 Web 目录复制到 OS X Sites 文件夹,那么当我以这种方式访问它时,该小程序可以从浏览器正常工作。
但是,如果我运行 GlassFish 并访问我的 Web 应用程序,则该小程序不会运行。相反,我在浏览器 java 控制台中收到这些错误:
java.lang.ClassFormatError: Incompatible magic value 1768779887 in class file tskApplet
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at sun.plugin2.applet.Applet2ClassLoader.findClass(Applet2ClassLoader.java:219)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Plugin2ClassLoader.java:249)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:179)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:160)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Plugin2ClassLoader.java:674)
at sun.plugin2.applet.Plugin2Manager.createApplet(Plugin2Manager.java:2990)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1481)
at java.lang.Thread.run(Thread.java:680)
有什么建议下一步该看哪里吗?
For a programming assignment, I am trying to have a GlassFish server serve up a client applet to talk to the server servlet. I've been stuck on having GlassFish deliver the applet. I have been searching extensively on this, and am not finding anything that resolves the issue - though I am learning quite a bit.
I have a 'hello world' applet compiled to tskApplet.class.
import java.applet.Applet;
import java.awt.*;
public class tskApplet extends Applet {
public void paint (Graphics g) {
g.drawString("Hello world! It's an applet!", 5, 25);
}
}
I have an html page that loads the applet with the following applet tag:
<applet code = "tskApplet.class" width="300" height="300"></applet>
I've tried (to no avail) all sorts of variations such as putting the .class file in a .jar and including archive="tskApplet.jar" in the applet tag, and using a .jsp page, etc.
I'm using IntelliJ and if I run the tskApplet from an applet run/debug configuration it works fine. I followed this guide to set up GlassFish with ImtelliJ: http://wiki.jetbrains.net/intellij/Developing_applications_for_GlassFish_Server_in_IntelliJ_IDEA
If I copy the exact same .class file and .html file from the GlassFish server's web directory to the OS X Sites folder, then the applet works fine from the browser when I access it that way.
But if I run GlassFish and access my web application, the applet does not run. Instead I get these errors in the browser java console:
java.lang.ClassFormatError: Incompatible magic value 1768779887 in class file tskApplet
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at sun.plugin2.applet.Applet2ClassLoader.findClass(Applet2ClassLoader.java:219)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Plugin2ClassLoader.java:249)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:179)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:160)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Plugin2ClassLoader.java:674)
at sun.plugin2.applet.Plugin2Manager.createApplet(Plugin2Manager.java:2990)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1481)
at java.lang.Thread.run(Thread.java:680)
Any suggestions where to look next?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来 GlassFish 运行的 JVM 比编译 Applet 的 JVM 更旧。找出服务器正在运行的 JVM。
Sounds like GlassFish is running with an older JVM than the Applet was compiled with. Find out what JVM the server is running.