现在想说的说如何在你的页面中插入applet 。
在源代码中含有html文件夹,这里面分别有applet.html和applet2.html,等会儿看到代码后大家就知道是什么意思了。
applet.html:
<object codetype="application/java" id="TestApplet" codebase = "." name="testApplet" align="middle" code="applet.TestApplet.class" width="400" height="400">
</object>

<script>...
if(window.document.testApplet != null) ...{
try ...{
var dummy = window.document.testApplet.getURLName();
}
catch(e) ...{
alert("Java Run-time Environment(JRE) cannot be found on your computer. Please download JRE(Ver.>=5.0) at SUN corp. http://www.sun.com Downloads->Java SE->Java Runtime Environment (JRE)");
}
}
</script>
这里面的JavaScript是用于检查applet是否被正常地加载,如果没有被正常加载一般是由于客户电脑上没有安装JRE,并提示下载安装。当然也有一些情况也会导致不正常地加载,不过这些就需要开发者进行解决了。
applet2.html:
<object codetype="application/java" id="TestApplet2" codebase = "." name="testApplet2" align="middle" code="applet.TestApplet.class" width="400" height="400">
</object>

<script>...
if(window.document.testApplet2 != null) ...{
try ...{
var dummy = window.document.testApplet.getURLName();
}
catch(e) ...{
alert("Java Run-time Environment(JRE) cannot be found on your computer. Please download JRE(Ver.>=5.0) at SUN corp. http://www.sun.com Downloads->Java SE->Java Runtime Environment (JRE)");
}
}
</script>
这部分和applet.html差不多,仅仅就是object 标签中的name变成了testApplet2用于区分第一个applet对象。这样JavaScript才不会搞错。
下面介绍一下在JSP中插入这个applet的方法:
如果是在一个页面中插入一个这样的apple t:

<%...
String preBasePath = request.getContextPath();
%>
<html:html>
<head>
<script src="<%=preBasePath%>/JSP/js/AppletAccess.js"></script>
</head>
<body class="basic" onload="accessApplet()" marginheight="0" marginwidth="0" rightmargin="0" topmargin="0"
leftmargin="0">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td>
<%...@ include file="/html/applet.html" %>
</td>
</tr>
</table>
</body>
<html>
这里很明显可以看到插入这个applet只需一个include语句就行,非常方便。
以上是插入一个小应用程序的方法,如果要插入两个也不难:

<%......
String preBasePath = request.getContextPath();
%>
<html:html>
<head>
<script src="<%=preBasePath%>/JSP/js/AppletAccess.js"></script>
</head>
<body class="basic" onload="accessAppletDual()" marginheight="0" marginwidth="0" rightmargin="0" topmargin="0"
leftmargin="0">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td>
<%... @ include file="/html/applet.html" %>
<%... @ include file="/html/applet2.html" %>
</td>
</tr>
</table>
</body>
<html>
大家可以对比一下。
本文介绍如何在HTML和JSP页面中插入Java Applet,包括单个和多个Applet的实现方法,以及如何通过JavaScript检查Applet是否成功加载。
456

被折叠的 条评论
为什么被折叠?



