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();
}
}
According to the Java Language Specification, a proper
.classfile has starts with the magic number :If you open any compiled
.classfile with a hex editor and inspect its first bytes, they should be0xCAFEBABE.1013478509in ASCII translates to<htm.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.