---
title: "Web中使用Applet的方法"
author: "wnzz95391511"
date: "2009-04-02T13:42:07Z"
tags: []
categories: ["Web前端"]
slug: "web-applet"
draft: false
lastmod: "2009-04-02T13:42:07Z"
id: 359825
url: "https://perfectlife.iteye.com/blog/359825"
---

**Applet这东西，以前没有使用过，更没有在jsp页面中使用。这次必须要在jsp中使用Applet显示图，也就来学了一学。**
在网上查了一些使用方法。

JSP中嵌入applet使用<jsp:plugin/>标签

我使用的applet类是
AlarmSpeedApplet.class，在com.wlwh.chart.linechart包中。测试JSP为AppeltJsp.jsp
<jsp:plugin>标签定义如下：

```java

<jsp:plugin type="applet"
			code="com.wlwh.chart.linechart.AlarmSpeedApplet.class"
			codebase="plugin"
			width="600" height="600">
		</jsp:plugin>

```

目录结构如下
...WEBROOT
.......plugin
..........com
.............wlwh
.................chart
......................linechart
..............................AlarmSpeedApplet.class
.......WEB-INF
.......AppletJsp.jsp

**运行后，AlarmSpeedApplet类被浏览器找到了，却发现不了AlarmSpeedData类。原来applet类使用的类，也需要被包含进来。修改如下：**

```java

<jsp:plugin type="applet"
			code="com.wlwh.chart.linechart.AlarmSpeedApplet.class"
			codebase="plugin"
			archive="AlarmSpeedData.class,AlarmSpeed.class,jfreechart-1.0.8.jar,jfreechart-1.0.8-experimental.jar,jfreechart-1.0.8-swt.jar,jcommon-1.0.12.jar"
			width="600" height="600">
		</jsp:plugin>

```

**将类所需要的包也加入了进来，目录结构如下**
...WEBROOT
.......plugin
..........com
.............wlwh
.................chart
......................linechart
..............................AlarmSpeedApplet.class
..............................其他同包下所被用到的类
...........所有使用的jar包
.......WEB-INF
.......AppletJsp.jsp

**如此，运行成功了！**