Search code examples
javahtmlstandards-complianceapplet

What is the best way of embedding a java applet into my webpage?


I've been looking into putting a little Java application in my web page, but the more research I do, the more confused I become about how I should do it. Sun suggests many ways of doing it, but it looks suspiciously like it's from the Netscape era.

So, should I use <applet>, as suggested by eclipse, <embed>, or <object>?

And how should I use the correct tag?


Solution

  • Since Java 6 Update 10 they've released a Java Deployment Kit:

    The Java Deployment Toolkit makes deploying Java applets or Java Web Start programs a snap. The Deployment Toolkit JavaScript file provides:

    * Accurate detection of installed JREs
    * Seamless JRE installation
    * Complete applet launching (JRE detection and, if necessary, upgrading) 
      in a single line of code
    * Complete Web Start program launching in a single line of code 
    

    The following HTML code is all it takes to ensure that Java 1.6 is installed and then a Java applet is launched:

    <script src="http://java.com/js/deployJava.js"></script>
    
    <script>
      deployJava.runApplet({codebase:"http://www.example.com/applets/",
         archive:"ExampleApplet.jar", code:"Main.class",
         width:"320", Height:"400"}, null, "1.6");
    </script>