不相容的魔法值1013478509"当与服务器和QUOT推出的Java小程序失败;

编程入门 行业动态 更新时间:2024-10-14 00:29:52
本文介绍了不相容的魔法值1013478509"当与服务器和QUOT推出的Java小程序失败;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我和我的小程序有问题。我有一所学校项目中,我应该做一个乒乓球网络游戏。它运行正常离线,但是当我尝试从服务器加载,我只是得到一个空框,在一个红色的文字。当我点击的文字我得到的消息:

  

不兼容的魔法值1013478509

我使用码头,全8.1.8.v20121106.jar,和servlet-API-3.0.jar

这是启动服务器的类看起来是这样的:

TheServer扩展公共类的HttpServlet {    私有静态最后的serialVersionUID长1L =;    私人扫描仪SC;    私人字符串网站;    私人的PrintWriter出来;    @覆盖    保护无效的doGet(HttpServletRequest的REQ,HttpServletResponse的RESP)抛出了ServletException,IOException异常{        resp.setContentType(text / html的;字符集= UTF-8);        resp.setStatus(HttpServletResponse.SC_OK);        OUT = resp.getWriter();        SC =新的扫描仪(新的文件(F:\\\\ \\\\用户\\\\的Johan工作区航向对接5 \\\\ \\\\ PongOnline斌\\\\ pong.html));        网站=;        而(sc.hasNext())            网站+ = sc.nextLine();        sc.close();        通过out.println(网站);        的System.out.println(网站);    }    公共静态无效的主要(字符串参数... args)抛出异常{        ServletContextHandler语境=新ServletContextHandler(ServletContextHandler.SESSIONS);        context.addServlet(TheServer.class,/);        Server服务器=新服务器(666);        server.setHandler(上下文);        server.start();        server.join();    }}

解决方案

有效的Java类的魔法值是 0xCAFEBABE (的十六进制值 3405691582 ),这是第一个4个字节。但是,你得到 0x3C68746D (的十六进制值 1013478509 ),这又代表了ASCII字符< , ^ h , T 和米。要看到它自己,运行这块code的:

INT魔法= 1013478509;的ByteBuffer B = ByteBuffer.allocate(4);b.putInt(魔法);的System.out.println(新的String(b.array()));

这与通过网站提供服务的小程序组合表明,它是一个&LT的开始; HTML方式> 标签,它反过来又表明它是一个HTML文档

那么,HTTP请求Applet已被明显的真正的返回的HTML文档。你应该能够看到它自己,当你改变当前请求的URI在浏览器地址栏中指向applet的URL。然后你会看到浏览器的真正的检索,当它试图下载该小程序。也许是在一个HTML页面的味道一个简单的HTTP 404错误的文件。

要解决这个问题,只要确保在URL中的<小程序> 或<对象> 标签是正确的。当您在浏览器地址栏中看到这是相对于当前请求的URL。你的servlet是如何工作的方式是很奇怪。你从deploy文件夹外流HTML文件。这表明,该小程序也是部署文件夹外,因而无法到达通过一个有效的URL的。你应该把两者的HTML页面,并在网页内容文件夹中的小程序。这样,您就不需要这个servlet了。

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:

incompatible magic value 1013478509

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(); } }

解决方案

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 <html> 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 <applet> or <object> 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.

更多推荐

不相容的魔法值1013478509&QUOT;当与服务器和QUOT推出的Java小程序失败;

本文发布于:2023-11-17 02:43:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608516.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不相容   服务器   程序   魔法值   QUOT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!