在html页面嵌入applet异常处理办法

1、java代码

public class HelloWorldApplet extends Applet {
	/**
	 * @Description: TODO(这里用一句话描述这个类的作用)
	 * @date 2017年7月4日 上午8:49:56
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void paint(Graphics g) {
		g.drawString("Hello World", 25, 50);
	}

	
}
引入的架包:

import java.applet.*;
import java.awt.*;


2、编写html页面

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	String lang = "" + session.getAttribute("lang");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
	<hr>
	<applet code="pers.wxp.applet.HelloWorldApplet.class" codeBase="."
		archive="<%=basePath%>/jar/helloword.jar" width="320" height="120"> If
		your browser was Java-enabled, a "Hello, World" message would appear
		here. </applet>
	<hr>
</body>
</html>


注意问题:报异常

(1)一定加入以下代码,获取工程根目录

%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	String lang = "" + session.getAttribute("lang");
%>

不然一直报找到的类为空异常。


(2)code="pers.wxp.applet.HelloWorldApplet.class"写的是包名+类名。单独写类名同样报错。


(3)必须将此类打包成jar文件,如何打包如下:
详细介绍:http://jingyan.baidu.com/article/5bbb5a1b280d0113eba179ce.htm
archive="<%=basePath%>/jar/helloword.jar"


4、html标签的<applet>介绍

详细介绍:http://www.runoob.com/tags/tag-applet.html


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值