This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I'm trying to load an applet I wrote from a web page (JSP). It will load just fine when I do it locally inside an HTML page, but when I try accessing it from the web server it says that the applet cannot be found.
Here is what I have:
The page loads fine but the applet will not load because it cannot find the DisplayMonoApplet.class.
Here is the exact error:
load: class DisplayMonoApplet.class not found. java.lang.ClassNotFoundException: DisplayMonoApplet.class at sun.applet.AppletClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.applet.AppletClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.applet.AppletClassLoader.loadCode(Unknown Source) at sun.applet.AppletPanel.createApplet(Unknown Source) at sun.plugin.AppletViewer.createApplet(Unknown Source) at sun.applet.AppletPanel.runLoader(Unknown Source) at sun.applet.AppletPanel.run(Unknown Source) at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: open HTTP connection failed. at sun.applet.AppletClassLoader.getBytes(Unknown Source) at sun.applet.AppletClassLoader.access$100(Unknown Source) at sun.applet.AppletClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) ... 10 more
My DisplayMonoApplet can be found in the WAR file in the following location: WEB-INF\classes\myapp\DisplayMonoApplet.class
The applet class files are requested directly from the webserver by the browser. Therefore, they have to be in publically accessible web space. They cannot be anywhere inside of WEB-INF, because this directory is quite deliberately not served from.
Basically, the applet class files need to be at the top level of the web app, or in a jar file at some stated path below that top level -- but not in WEB-INF.
Well, being at home I couldn't try the actual case decribed above, but I worked up a quick test using the old Applet tag and not loading the plugin and did a quick HelloWorld style applet, and sure enough as you thought, it works when I put the applet at the top (not inside the web-inf)!
On Monday I'll convert what I have at work to the way you suggest and see if it still works with the extra plugin code and all.
I've never distributed an applet (servlets yes...plenty of those) through a web server before and didn't know it was restricted that way.