How do I load an applet from a servlet or JSP? Where do I place my applet class files?
It is best to think of the set of applet class files as entirely different from the set of servlet class files. They will be loaded by different Virtual Machines, and may even have different versions of classes. It is a simple matter to configure your build environment (Ant or make) to create copies of common class files in the two different classpath directories.
Since the concept of "current directory" is kind of fuzzy in the Servlet API, it is usually easiest to make a separate directory just for your applet class files, and use the optional CODEBASE parameter to the APPLET tag. Here is an architecture that works well:
myapp/WEB-INF/classes/MyServlet.class myapp/WEB-INF/classes/Util.class myapp/index.html myapp/applets/MyApplet.class myapp/applets/Util.classThen if your servlet generates a line like:
out.println("&lt;APPLET CODE='MyApplet.class' WIDTH=50 HEIGHT=50 CODEBASE='/applets'&gt;"&gt;;The browser will be able to load MyApplet.class and Util.class from your /applets web directory. It will not be able to load anything from WEB-INF/classes, since those files are accessible only by the servlet engine.