Object Creation in HTML

Client-side objects, like those we discussed briefly in Chapter 6, are created with a variety of HTML tags. The two most common are the <OBJECT> tag and the <APPLET> tag. APPLET is generally only used to specify Java applets, while OBJECT can be used, depending on the browser, to specify any arbitrary object of any type.

Using Java Applets

The use of the <APPLET> tag is relatively simple. Here's a sample example:

  <APPLET CODE="MyClass.class" WIDTH=10 HEIGHT=10>

The CODE attribute's value is the name of the Java .class file that implements the applet. With this name, the browser can request that the server send the .class file. When it arrives, it can interpret it and display the results within the browser, or in a separate window if the applet has been so designed. APPLET also supports the WIDTH and HEIGHT attributes that tell the browser how wide and how tall the space it devotes to the applet should be.

However, hooking up script code to a Java applet isn't as straightforward. How we do it depends on whether we're using Internet Explorer or Navigator, and sometimes (as with Navigator) can even require a complete recompile of our Java applet. We're used to using Active Scripting languages with ASP, and Navigator and Internet Explorer enable script code to be connected to Java applets in very different ways. Since we're not going to be covering these dissimilar methods, we won't spend too much time talking about them here. These browsers don't ship with any Java applets we can use for a demonstration anyway. If you do have the .class file for a Java applet on your machine (perhaps from experimentation with Java development) feel free to load up a page and compare the HTML with that used for ActiveX controls—which we'll look at next.

Using ActiveX Controls

Their programming model is simple, and will be very familiar to someone with ASP experience. ActiveX Controls are created in HTML with the <OBJECT> tag. This tag, developed and endorsed by the World Wide Web Consortium (W3C), is extendable and can be used to insert any arbitrary object (including Java applets). Currently, its most common use is with ActiveX controls.

© 1997 by Wrox Press. All rights reserved.