java applet fail when launched with server “incompatible magic value 1013478509”

前端 未结 3 1471
情书的邮戳
情书的邮戳 2021-01-21 02:38

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

3条回答
  •  失恋的感觉
    2021-01-21 03:20

    The magic value of a valid Java class is 0xCAFEBABE (the hex value of 3405691582), which is the first 4 bytes. But you're getting 0x3C68746D (the hex value of 1013478509) which in turn stands for the ASCII characters <, h, t and m. To see it yourself, run this piece of code:

    int magic = 1013478509;
    ByteBuffer b = ByteBuffer.allocate(4);
    b.putInt(magic);
    System.out.println(new String(b.array()));
    

    This in combination with the applet being served by a website suggests that it's the start of a tag which in turn suggests that it's a HTML document.

    So, the HTTP request to applet has apparently actually returned a HTML document. You should be able to see it yourself when you change the current request URI in browser address bar to point to applet's URL. Then you'll see what the browser actually retrieved when it tried to download the applet. Perhaps it's a simple HTTP 404 error document in flavor of a HTML page.

    To fix it, just make sure that the URL in the or tag is correct. It's relative to the current request URL as you see in browser address bar. The way how your servlet works is quite strange. You're streaming a HTML file from outside the deploy folder. This suggests that the applet is also outside the deploy folder and thus not reachable by a valid URL at all. You should put both the HTML page and the applet in the web content folder. This way you don't need that servlet anymore.

    提交回复
    热议问题