O'Reilly logo

Java Servlet & JSP Cookbook by Bruce W. Perry

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

17.1. Embedding an Applet in a JSPUsing jsp:plugin

Problem

You want to use the jsp:plugin standard action to execute a Java applet with the Java Plug-in software.

Solution

Use the jsp:plugin action positioned in the area of a JSP where you want the applet to appear.

Discussion

The JSP specification provides a standard action, jsp:plugin, which produces the object and embed tags that are designed to allow browsers to load a Java applet. The action will run the applet using Sun Microsystems's Java Plug-in or initiate the download of the Plug-in if the user has not yet installed the Plug-in.

Tip

The Java Plug-in is designed to execute an applet using Sun Microsystems's Java 2 Runtime Environment, rather than any Java runtime provided by the browser. The installation of the Java JRE or Software Development Kit automatically installs the Java Plug-in.

Use nested jsp:param elements to provide the applet with any necessary parameter and value pairs. The jsp:param elements must be nested within a single jsp:params element.

Example 17-1 shows a JSP file that uses jsp:plugin to embed an applet named Clock.class. In this case, the Clock.class file is located in the same directory as the JSP in Example 17-1.

Tip

This applet originates from Sun Microsystems's sample applets: http://java.sun.com/products/plugin/1.4.1/demos/plugin/applets/Clock/example1.html

Example 17-1. Embedding a Java applet with jsp:plugin

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %> <jsp:useBean id="date" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required