Search code examples
htmlapplet

Accessing a java applet from another directory


I have a apple named "WelcomeApplet" in the following directory:

C:\project\applets\WelcomeApplet.class

And I have a html file here: C:\project\html\index.html

Now I am trying to access that applet in my code using this tag:

<applet CODE="../applets/WelcomeApplet.class" WIDTH="250" HEIGHT="150"></applet>

But this does not work! I copyed the applet to same fodler as my html file is and just pointed in CODE tag the name of the file then it worked. Am I providing wrong relative path or the CODE tag only should have the file name?


Solution

  • <applet 
        CODEBASE="../applets/"
        CODE="WelcomeApplet" 
        WIDTH="250" 
        HEIGHT="150">
    </applet>
    

    The code attribute should be the fully qualified name of the class, i.e. WelcomeApplet not WelcomeApplet.class. It is the codebase that specifies where to find the 'root' of the class file location.