----------------testapplet.htm---------------<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<applet name="testApplet" code="test.TestApplet.class" codebase = "." width="32" height="32">
</applet>
<script language="JavaScript" type="text/JavaScript">
alert("haha");
alert(window.document.testApplet.getStr());
</script></body>
</html>------------- TestApplet.java -----------------
package applets;import java.applet.Applet;
import java.util.*;import java.math.BigDecimal;;public class TestApplet extends Applet { /**
*
*/
private static final long serialVersionUID = 1L; public HashMap getHashMap()
{
HashMap hm = new HashMap();
hm.put("NAME", "myname is jim");
hm.put("VAL", new BigDecimal(999));
return hm;
} public String getStr()
{
return "8888";
}
}
----------------------------------------------------
testapplet.htm同级目录下有文件夹applets,TestApplet放在其中服务器:tomcat5.5
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<applet name="testApplet" code="test.TestApplet.class" codebase = "." width="32" height="32">
</applet>
<script language="JavaScript" type="text/JavaScript">
alert("haha");
alert(window.document.testApplet.getStr());
</script></body>
</html>------------- TestApplet.java -----------------
package applets;import java.applet.Applet;
import java.util.*;import java.math.BigDecimal;;public class TestApplet extends Applet { /**
*
*/
private static final long serialVersionUID = 1L; public HashMap getHashMap()
{
HashMap hm = new HashMap();
hm.put("NAME", "myname is jim");
hm.put("VAL", new BigDecimal(999));
return hm;
} public String getStr()
{
return "8888";
}
}
----------------------------------------------------
testapplet.htm同级目录下有文件夹applets,TestApplet放在其中服务器:tomcat5.5
</applet>code = "test.TestApplet.class" 有问题
我的路径是在webapp/exam/test
http://localhost:8080/exam/test/testapplet.htm,
然后就成功了