在用IE浏览时在网页上无法显示运行结果,主要是找不到MyApplet.class文件,我是把MyApplet.class和MyApplet.java这两个文件放到一个文件夹中的,但还是找不到,请问一下大家"code="这句该怎样写,才能找到MyApplet.class文件。
 
忽略了package的后果
源文件helloapplet.java因为在package applet中,所以在源文件第一行会有这样一行东西:
package applet;
......
在eclipse里运行小应用程序没有问题,但是用ie浏览器运行html文件,或者用appletviewer命令运行html文件,都会抛出class not found的异常。
helloapplet.html代码如下:
<html>
<head>
<title>Hello Applet!</title>
</head>
<body>
<applet code="helloapplet.class" width=300 height=100>
</applet>
</body>
</html>
在网上查了下,修改如下:
<applet code="helloapplet.class" codebase="D:\eclipseworkspace\helloworld\bin\applet" width=300 height=100>
</applet>
codebase指出class文件所在的基地目录,但是还是报相同的错误,折腾了很久,后来光华版友指出,错误和源文件第一行package语句有关。
于是想到引用包内定义类的格式应该是applet.helloapplet,那么对应的二进制文件引用方法也应该改为applet.helloapplet.class。于是做出
如下修改:
<applet code="applet.helloapplet.class" codebase="D:\eclipseworkspace\helloworld\bin" width=300 height=100>
</applet>

百度了好久找到的。。。MARK