ClassFormatError - Incompatible magic value

4.4k views Asked by At

I try use applet in my web application.

Applet class:

public class TestApplet extends JApplet {

    @Override
    public void init() {
        try {
            System.out.println("Applet!");
            SwingUtilities.invokeAndWait(new Runnable() {
                @Override
                public void run() {
                    JLabel lbl = new JLabel("Hello World");
                    add(lbl);
                }
            });
        } catch (Exception e) {
            System.err.println("createGUI didn't complete successfully");
        }
    }
}

In JSP:

<applet code="TestApplet.class" width="320" height="120" ></applet>

But when I load page after loading applet, I get this error.

ClassFormatError - Incompatible magic value 168430090 in class file TestApplet.

In my app I use Spring Security - if it's relevant.

1

There are 1 answers

0
stripybadger On BEST ANSWER

I've seen this error before when the server sent back an error page or login page instead of the jar/class file. You can use something like fiddler to look at what your webserver is actually sending back to your browser, you should be able to see what it's sending back. A lot of appservers now set httpOnly=true on their cookies, and a bug in the java browser plugin means that it doesn't send the jsessionid when requesting jars. Obviously this only really applies if you're using form-based authentication or similar.