(JSP)在文本域中显示超链接——如何在JSP中插入applet

        现在想说的说如何在你的页面中插入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 >

 

        大家可以对比一下。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值