[ Team LiB ] |
![]() ![]() |
Recipe 17.1 Embedding an Applet in a JSPUsing jsp:pluginProblemYou want to use the jsp:plugin standard action to execute a Java applet with the Java Plug-in software. SolutionUse the jsp:plugin action positioned in the area of a JSP where you want the applet to appear. DiscussionThe 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. 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.
Example 17-1. Embedding a Java applet with jsp:plugin<%@ 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>
<jsp:plugin type="applet" code="Clock.class" codebase=
"http://localhost:8080/home/applets" jreversion="1.4.1">
<jsp:params>
<jsp:param name="scriptable" value="false"/>
</jsp:params>
<jsp:fallback>
Sorry, we are unable to start the Java plugin <br />
</jsp:fallback>
</jsp:plugin>
<br /><c:out value="${date}"/>
</body>
</html>
Users who have installed Internet Explorer for Windows depend on an HTML object tag to provide the direction for loading the applet. In browsers that support the Netscape-style plug-in, the HTML uses it's embed tag. The jsp:plugin standard action generates HTML that should work with both browser types (but you still should test the resulting JSP, of course). Example 17-2 shows the HTML tags generated by the jsp:plugin action when the Internet Explorer 5.5 and the Netscape browsers request the JSP in Example 17-1. Example 17-2. HTML tags generated by the jsp:plugin action for loading a Java applet<OBJECT classid= clsid:8AD9C840-044E-11D1-B3E9-00805F499D93 codebase= "http://java.sun.com/products/plugin/1.2.2/jinstall-1_2_2-win.cab# Version=1,2,2,0"> <PARAM name="java_code" value="Clock.class"> <PARAM name="java_codebase" value="http://localhost:8080/home/applets"> <PARAM name="type" value="application/x-java-applet;version=1.4.1"> <PARAM name="scriptable" value="false"> <COMMENT> <EMBED type="application/x-java-applet;version=1.4.1" pluginspage= "http://java.sun.com/products/plugin/" java_code= "Clock.class" java_codebase= "http://localhost:8080/home/applets" scriptable="false"/> <NOEMBED> Sorry, we are unable to start the Java plugin <br /> </NOEMBED> </COMMENT> </OBJECT> Figure 17-1 shows the JSP with the embedded applet. Figure 17-1. A JSP with an embedded applet![]() See AlsoThe Java Plug-in technology page: http://java.sun.com/products/plugin/; Recipe 17.2 on embedding an applet using the Sun Microsystems HTML Converter. ![]() |
[ Team LiB ] |
![]() ![]() |