Applet loading error in Struts web project
I'm getting frustrating errors related with "ClassNotFoundException" when I try to load an applet by using tag inside a JSP file within a Struts web project:
load: class com.superdeporter.audio.AudioApplet.class not found.
java.lang.ClassNotFoundException: com.superdeporter.audio.AudioApplet.class
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: open HTTP connection failed:http://localhost:8080/SampleAudioApplication/com/superdeporter/audio/AudioApplet/class.class
at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
And this is the applet code within a JSP file:
<jsp:plugin type="applet" name="AudioApplet"
code="AudioApplet.class" codebase="/com/superdeporter/audio" width="100"
height="100" align="middle" jreversion="1.5"
archive="">
</jsp:plugin>
This seems to be a strange problem. By the 开发者_JAVA技巧way, let me say I have tried many combinations of code and codebase parameters and I was still getting the same errors. As I know, code parameter should have the name of Applet class as value and codebase parameter should have that applet class' package path as the value. Am I wrong?
Can anyone who faced this problem share his/her opinions with me? Is there a solution to this problem? Any suggestions on how to use applets within a Struts web project are also welcome.
The codebase parameter is actually the location of the applet class file on the server relative to the jsp page that is calling the applet. The applet class needs to be in a directory that is publicly accessible, so the standard /WEB-INF/classes directory won't work.
The fastest path to get something working would be to omit the codebase parameter completely and just put AudioApplet.class in the same directory as the jsp. See below for an example:
<jsp:plugin type="applet"
code="AudioApplet.class"
width="500"
height="500"
align="middle"/>
精彩评论