views:

333

answers:

3

Hi guys,

Ive got a problem with loading an applet from WEB-INF/classes directory. The main class of an applet (MainApplet.class) is there in the package aaa, but when loading I got the exception java.lang.ClassNotFoundException. Where am I wrong? My jsp is in Web Pages dir.

< jsp:plugin type="applet" code="aaa/MainApplet.class" jreversion="1.6" width="700" height="500" >

Thanks in advance for the reply!

A: 

Let's think about how that would work. An applet is executed in the browser. That is, somehow the browser needs to download your classfile(s). Classes in a webapplication's classpath are typically not made accessible to the browser; the browser wants the HTML these classes generate, not the classes themselves.

Bottom line: Applet classes and web application classes are executed on different machines, and therefore reside in different classpaths.

To correct your problem, read the documentation of jsp:plugin, particularly about the codebase attribute.

meriton
Nice, I set the <code> codebase </code> attribute to "classes", but still no result. Any idea?
Bruce
A: 

I have added < codebase = "classes" > but still does not work. Could someone provide me an example?

Cheers.

Bruce
Please do not post updates or comments as answers. Use the question's `edit` link to update the question and use the `add comment` link to add a comment.
BalusC
+1  A: 

Rather package the Applet-specific classes in a JAR file and put this JAR file in public webcontent. The /WEB-INF folder is not public accessible. Only this way the client can download the JAR file with all classes into the local environment at once and execute the applet. I'd also rather use the <object> tag above the legacy <jsp:plugin>. E.g:

<object type="application/x-java-applet" width="300" height="200">
    <param name="archive" value="AppletJAR.jar">
    <param name="code" value="com.example.AppletClass">
</object>

For more detailed examples see this Sun article.

BalusC