I've seen a few people run into this issue. If you have a JSP page which contains an applet HTML tag or a similar JSP tag to embed and applet, how do you set the codebase? The first thought most have(including myself) is to stick your applet jar file in the web app's WEB-INF/lib directory and attemot to use some varation of that path:
/myapp/WEB-INF/lib
myapp/WEB-INF/lib
/WEB-INF/lib
WEB-INF/lib
To understand why this will NOT work you need to understand what is happening behind the scenes. When the page loads in the user's browser an HTTP request is made to a servlet running which handles HTTP requests. Now, here is the important part... the servlet CAN'T serve files located underneath the WEB-INF directory. It is off limits. So while your relative URL specified in the codebase attribute may make perfect sense, the servlet will likely return an "access forbidden" HTTP header. The JRE in the user browser then interprets this incorrectly(since it's expecting an applet) and throws a wild exception complaining about a bad "magic number." Quickly, a magic number in Java land just is a way of distinguishing what the "type" of file is, e.g. a .class file, a .jar file, etc. In fact if you open up a .class file in a hex editor you can see the hex representation of the magic number for this type of file(which is humerously CAFEBABE).
But to get back on track... you simply need to move your .jar file outside of WEB-INF into... say... a directory called applet. So you would have myapp/applet/myjar.jar. The path you would specify in the codebase attribute would then be:
codebase="/myapp/applet"
Also, be sure to set the attribute:
archive="myjar.jar"
in the applet/object/jsp tag you're using.
When I first encountered my "problem" I though it had to do with liferay but it doesn't. This is simply how the JSP engine(at least for tomcat and likely others) works.
Hope this helps a bunch of people.
Please sign in to flag this as inappropriate.