在web上运行applet时,类未找到异常和IO异常

时间:2010-12-02 12:08:22

标签: java swing jsp applet

这是我的jsp文件正文标记。

<body>
   <jsp:plugin type="applet" code="SApplet.class" 
        codebase="C:\Program Files\apache-tomcat-6.0.18\webapps\testweb\WEB-INF\classes" 
        width="400" 
        height="300" jreversion="1.6"></jsp:plugin>


  </body>

我想在Web应用程序上运行我的applet,但是我在一个小窗口上获取了以下错误。我在控制台上无法获得任何错误。

Java Plug-in 1.6.0_20
Using JRE version 1.6.0_20-b02 Java HotSpot(TM) Client VM
User home directory = C:\Documents and Settings\Sandy
----------------------------------------------------
c:   clear console window
f:   finalize objects on finalization queue
g:   garbage collect
h:   display this help message
l:   dump classloader list
m:   print memory usage
o:   trigger logging
q:   hide console
r:   reload policy configuration
s:   dump system and deployment properties
t:   dump thread list
v:   dump thread stack
x:   clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------
load: class SApplet.class not found.
java.lang.ClassNotFoundException: SApplet.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/testweb/SApplet/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)
 ... 7 more
Exception: java.lang.ClassNotFoundException: SApplet.class
load: class SApplet.class not found.
java.lang.ClassNotFoundException: SApplet.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/testweb/SApplet/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)
 ... 7 more
Exception: java.lang.ClassNotFoundException: SApplet.class

1 个答案:

答案 0 :(得分:1)

您的代码库写错了。它应该是一个相对的web路径。

在你的情况下,它应该像testweb / applet-classes。但是将所有applet类放在那里,而不是在WEB-INF下。 WEB-INF是一个应该存储在服务器端运行的类的地方。可能无法从Web访问此文件夹。 applet类由运行到浏览器中的JVM下载,因此WEB-INF可能对它不可见。

更好的方法是将applet类打包到jar文件中,甚至将它放在应用程序的根目录下。在这种情况下,您的代码库将类似于codebase='myapplet.jar'