Results 1 to 5 of 5
  1. #1
    mudjekeewis is offline Member
    Join Date
    Mar 2012
    Posts
    3
    Rep Power
    0

    Default Java Applet Location

    Hi, I've seen a lot of posts about this topic, but none that have helped me answer my question. I've been teaching myself from tutorials, so forgive me if I missed something simple. I created a new dynamic web app in Eclipse using Tomcat, and simply want to call an applet from a jsp. Here's what I have:

    In my working directory "test" I have the Tomcat standard: .settings, build, src, WebContent, .classpath and .project. I'm serving my own test/WebContent/index.html through the Tomcat server localhost at the URL http://localhost/test/ without any probelms. Next I made src/HelloWorld.java with the following code taken from an online tutorial:

    import java.applet.*;
    import java.awt.*;

    public class HelloWorld extends Applet {
    public void init() {}
    public void paint(Graphics g)
    {
    //method to draw text on screen
    // String first, then x and y coordinate.
    g.drawString("Hey hey hey",20,20);
    g.drawString("Hellooow World",20,40);
    }
    }

    The .class file for this is in build/classes/HelloWorld.class. Then, I created WebContent/AppletJsp.jsp with the following code:

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <body>
    <table class="title">
    <tr><th>Test Applet</th></tr>
    </table>
    <applet code="HelloWorld.class" codebase="/build/classes" width="200" height="200">
    Your browser does not support the <code>applet</code> tag.
    </applet>
    </body>
    </html>

    When I test this in my browser (chrome) at http://localhost/test/AppletJsp.jsp I see the words "Test Applet", but below them is just a square reading "Error. Click for details." Doing so gives me the following error message:

    load: class HelloWorld.class not found.
    java.lang.ClassNotFoundException: HelloWorld.class
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Un known Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(U nknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Un known Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Un known Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unk nown Source)
    at sun.plugin2.applet.Plugin2Manager.createApplet(Unk nown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Exception: java.lang.ClassNotFoundException: HelloWorld.class


    Can anyone explain how to correctly specify the codebase so that the browser can locate the .class file? Thanks.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Java Applet Location

    class HelloWorld.class not found.
    The class name here is probably wrong. That looks like a filename not a class name. Remove the .class to get the class name.

    For testing create a static html page and change that until it works.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    mudjekeewis is offline Member
    Join Date
    Mar 2012
    Posts
    3
    Rep Power
    0

    Default Re: Java Applet Location

    I moved the <applet> code to my index.html as you suggested, and also tried removing the .class from it, but with no success. Everything still works except for the applet, and the error message is the same as before (with or without .class). I do have another question that might help though. My html files are located in WebContent, so does that mean that my root URL begins there? (Since the URL http://localhost/test/ serves the index.html file in WebContent?) Does this mean that I need to change Eclipse's build parameters to output to a folder within test/WebContent, and not just within test?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Java Applet Location

    Sorry, I don't know anything about using your IDE or WebContent.

    If the class file were in the same folder as the html file and no codebase=, it should work.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    mudjekeewis is offline Member
    Join Date
    Mar 2012
    Posts
    3
    Rep Power
    0

    Default Re: Java Applet Location

    That's alright. Thanks for your advice.

Similar Threads

  1. Applet Image Problem (repaint(); location?)
    By dyelax in forum Java Applets
    Replies: 24
    Last Post: 12-01-2010, 07:29 PM
  2. Replies: 8
    Last Post: 08-25-2010, 04:22 PM
  3. java applet location
    By waqar100 in forum New To Java
    Replies: 0
    Last Post: 06-10-2010, 07:47 PM
  4. need to copy file from one location to another location
    By naveen.dpt2007 in forum New To Java
    Replies: 4
    Last Post: 02-28-2010, 03:53 PM
  5. Applet Image location
    By MarkWilson in forum NetBeans
    Replies: 3
    Last Post: 06-30-2008, 07:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •