使用服务器“不兼容的幻值 1013478509"启动时,java 小程序失败; [英] java applet fail when launched with server "incompatible magic value 1013478509"

查看:29
本文介绍了使用服务器“不兼容的幻值 1013478509"启动时,java 小程序失败;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的小程序有问题.我有一个学校项目,我应该在其中制作乒乓球在线游戏.它离线运行良好,但是当我尝试从服务器加载它时,我只得到一个带有红色文本的空框架.当我点击文本时,我收到消息:

I'm having a problem with my applet. I have a school project where I'm supposed to make a pong-online game. It runs fine offline but when I try to load it from a server I just get an empty frame with a red text in it. when I click the text I get the message:

不兼容的魔法值 1013478509

incompatible magic value 1013478509

我正在使用 jetty-all-8.1.8.v20121106.jar 和 servlet-api-3.0.jar

I'm using jetty-all-8.1.8.v20121106.jar, and servlet-api-3.0.jar

启动服务器的类如下所示:

The class that starts up the server looks like this:

public class TheServer extends HttpServlet {
    private static final long serialVersionUID = 1L; 
    private Scanner sc;
    private String webSite;
    private PrintWriter out;


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html; charset=UTF-8");
        resp.setStatus(HttpServletResponse.SC_OK);
        out = resp.getWriter();

        sc = new Scanner(new File("F:\\Users\\Johan\\Workspace Kurs 5\\PongOnline\\bin\\pong.html"));
        webSite = "";
        while(sc.hasNext())
            webSite += sc.nextLine();
        sc.close();

        out.println(webSite);
        System.out.println(webSite);
    }

    public static void main(String...args) throws Exception {
        ServletContextHandler context = new ServletContextHandler( ServletContextHandler.SESSIONS);
        context.addServlet(TheServer.class, "/");

        Server server = new Server(666);
        server.setHandler(context);
        server.start();
        server.join();
    }
}

推荐答案

根据Java 语言规范,一个正确的.class 文件以魔数开头:

According to the Java Language Specification, a proper .class file has starts with the magic number :

魔法项提供标识类文件的魔法编号格式;它的值为 0xCAFEBABE.

The magic item supplies the magic number identifying the class file format; it has the value 0xCAFEBABE.

如果你用十六进制编辑器打开任何编译的 .class 文件并检查它的第一个字节,它们应该是 0xCAFEBABE.1013478509 在 ASCII 中转换为 .

If you open any compiled .class file with a hex editor and inspect its first bytes, they should be 0xCAFEBABE. 1013478509 in ASCII translates to <htm.

确保您已在服务器上正确编译了该类.更有可能的是,正如 BalusC 在他的回答中已经指出的那样,确保 URL 是正确的.您得到的 <htm... 字节可能是服务器提供的 HTML 错误文档.

Make sure you've got the class properly compiled on the server. And more likely, as BalusC already pointed out in his answer, make sure URL's are correct. The <htm... bytes you're getting might be an HTML error document served by the server.

这篇关于使用服务器“不兼容的幻值 1013478509"启动时,java 小程序失败;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆