Forcing the Java 2 Plug-in to be used


Web browsers (such as Netscape Navigator or MS Internet Explorer) are not equipped to run Java 2 programs. To run Java 2 programs they need a plug-in, which is basically a special tool or piece of software that the browswer can get and plug-in in order to run special types of programs, such as Java programs (or various video or audio files). The Java Plug-in is discussed in Section 16.10 (pp. 803-804) in the text.

There are two things that must happen for a browser to be able to run a Java 2 applet. First, the Java Plug-in must be installed in the browser. Second, the HTML file that contains the applet must specify that it is to be run using the Java Plug-in rather than running Java via the web browser.

Sun provides this document describing how to write HTML files in order to force the Java Plug-in to be used.

You can read the details given in the above Sun link. To make it easier on you though, here is an example piece of code to force the browser to use the Java Plug-in to run homework5.class.

You can simply copy the above directly to your own HTML file and then change the following things:

Note: the HTML file can be upper or lower or mixed case.

The basic idea of the HTML code above is a follows. The OBJECT tag is a new tag that is in the HTML 4.0 standard used to tell the browser how to deal with document enriching content such as applets. It is supported by Intenet Explorer but not by Netscape (It was not recognized as of the LINUX version of 4.7). Netscape does support a tag called EMBED with a similar purpose to OBJECT but not part of the HTML 4.0 standard. So the above code contains a kludgy way to force the Plug-In on both browsers that support the OBJECT tag and those that support the EMBED tag. If your browser does support the OBJECT tag it will be used and because of the COMMENT subtag above the EMBED tag will be ignored. On the other hand, if you browser does not support the OBJECT tag all the subsequent tags up to the EMBED tag will be ignored and then if your browser supports the EMBED tag it will be used to force the Plug-In. If neither tag is supported then the message: No Plug-in support for APPLET... is printed. Let's look at code to force the plugin using just the OBJECT tag then just the EMBED tag to try to understand it. First, consider

<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
 width="500" height="300"
 codebase="http://java.sun.com/products/plugin/1.2.2/jinstall-1_2_2-win.cab#Version=1,2,2,0">
  <PARAM NAME="code" VALUE="homework5.class">
  <PARAM NAME="type" VALUE="application/x-java-applet">
  <PARAM NAME="scriptable" VALUE="true">
</OBJECT>

The classid tag is used to tell the browser that the content is a Java 2 applet so use the Plug-in. The width and height tags specify the dimensions of the applet. The codebase tag says where to get a plug-in for this content if none is available. The PARAM tags all contain information passed to the Plug-In once the browser runs it. The code parameter says which file contains the applet. The type parameter tells the Plug-In whether the content is an applet or a bean and if so what version of the Plug-In is required. i.e., VALUE="application/x-java-applet;version1.2.2" would require version 1.2.2. Unless you actually use a feature of the newer plug-ins I would recommend not specifying this attribute so that LINUX people who don't have more than a beta version of the Plug-In can see your applets. Finally the scriptable parameter says whether of not Javascript or VBScript can invoke the applet. Next let's look at the EMBED code to force the Plug-In:

     <EMBED type="application/x-java-applet"
        width="500" height="300" code="homework5.class"
        pluginspage="http://java.sun.com/products/plugin/1.2/plugin-install.html">
     </EMBED>

The type tag here justs tells the Netscape browser to handle the content according to how content of MIME type application/x-java-applet is handled in the netscape application preferences. i.e., if the the Plug-In is installed correctly use the Plug-In. The width and height tags specify the dimensions of the applet. The code tag specifies the filename of the applet code. Lastly, the pluginspage tag says where to go if the plug-in is not installed.