[ Team LiB ] |
![]() ![]() |
Recipe 17.2 Embedding an Applet in a JSP Using the HTML ConverterProblemYou want to use the Java Plug-in HTML Converter tool to generate the tags for embedding an applet. SolutionUse the HTML Converter tool within htmlconverter.jar, which is located in the lib directory of the directory where you have the Java SDK installed. DiscussionA busy developer can let the Java Plug-in HTML Converter tool produce the HTML tags that are responsible for loading Java applets. The Java Plug-in is a Java-based tool that allows applets to be run in the Sun Microsystems Java 2 runtime environment, rather than within the web browser's Java runtime environment. The Java Plug-in is installed on your machine when you install the JRE, including the installation of the SDK. The HTML Converter tool will convert a specified JSP file that contains an applet HTML tag, replacing the applet tag with a more complex tag collection that allows most browsers to load the Java applet. The Converter leaves the rest of your JSP code untouched; it only replaces the JSP's applet tag. Here is how to use the HTML Converter tool:
Figure 17-2. The HTML Converter (GUI version)![]()
Example 17-4 shows the code that replaced the applet tag in Example 17-3 (in bold font), as well as the code that the converter tool did not modify. Example 17-4. The object and embed tags produced by the HTML Converter<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<jsp:useBean id="date" class="java.util.Date" />
<html>
<head><title>A Clock in a JSP</title></head>
<body>
<h2>The time...</h2>
<!--"CONVERTED_APPLET"-->
<!-- HTML CONVERTER -->
<OBJECT
classid =
"clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
codebase =
"http://java.sun.com/products/plugin/autodl/jinstall-1_4-windows-
i586.cab#Version=1,4,0,0"
>
<PARAM NAME = CODE VALUE = "Clock.class" >
<PARAM NAME = CODEBASE VALUE = "http://localhost:8080/home/applets" >
<PARAM NAME = "type" VALUE = "application/x-java-applet;version=1.4">
<PARAM NAME = "scriptable" VALUE = "false">
<COMMENT>
<EMBED
type = "application/x-java-applet;version=1.4"
CODE = "Clock.class"
JAVA_CODEBASE = "http://localhost:8080/home/applets"
scriptable = false
pluginspage =
"http://java.sun.com/products/plugin/index.html#download">
<NOEMBED>
</NOEMBED>
</EMBED>
</COMMENT>
</OBJECT>
<!--
<APPLET CODE = "Clock.class" JAVA_CODEBASE =
"http://localhost:8080/home/applets">
</APPLET>
-->
<!--"END_CONVERTED_APPLET"-->
<br /><c:out value="${date}"/>
</body>
</html>
See AlsoThe Java Plug-in technology page: http://java.sun.com/products/plugin/; Recipe 17.1 on embedding a Java applet using the jsp:plugin standard JSP action. ![]() |
[ Team LiB ] |
![]() ![]() |