CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 18

Thread: Applet notinited

  1. #1
    Join Date
    Nov 2008
    Posts
    7

    Applet notinited

    Hi,

    I am adding an applet in a JSP page using an external javascript file. And I am constructing the Applet code based on the browser family (<EMBED> for Mozilla family and <OBJECT> for MS-Internet Explorer).

    JavaScript Code:
    var _app = navigator.appName;
    if (_app == 'Mozilla' || _app == 'Netscape')
    {
    document.write('<embed code="ButtonMoveApplet.class"',
    'width="200"',
    'height="200"',
    'type="application/x-java-applet;version=1.5"',
    'pluginspage="pluginspage="http://java.sun.com/javase/downloads/ea.jsp"',
    'archive="Appln.jar">');
    }
    else if (_app == 'Microsoft Internet Explorer')
    {
    document.write('<OBJECT ',
    'classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"',
    'width="200"',
    'height="200">',
    '<PARAM name="code" value="ButtonMoveApplet.class">',
    'archive="Appln.jar"',
    '</OBJECT>');
    }
    else
    { document.write('<p>Sorry, unsupported browser.</p>'); }

    I have JARed the applet program. I placed the jar file in the same place where my JSP page exists. I am getting an error msg in the browser's status bar --> applet ButtonMoveApplet notinited when I run this from the browser (http://localhost:8080/AppletApplication). When I checked in Java Console I found java.lang.ClassNotFoundException.

    My office network is configured to use a proxy. Is the browser doesn’t allow to load the applet because of the proxy? Or is there any other problem?

    Any help on this will be greatly appreciated

    Regards,
    Red Hunt

  2. #2
    Join Date
    Apr 2005
    Location
    Norway
    Posts
    3,934

    Re: Applet notinited

    Maybe you can use the Java Console Window to get more information on your problem (depending on your browser, your should find it somewhere in the browsers menu).

    - petter

  3. #3
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,858

    Re: Applet notinited

    What class was not found? Is it your class or a class that your program uses that you need to provide a jar file for?
    Can you see what HTTP GETs the browser issues (in a server trace) after it loads the HTML for the page with the APPLET? That could tell you where the browser thinks the jar file/class file is located.

    Have you tried using the <APPLET tag vs embed or object?
    Norm

  4. #4
    Join Date
    Nov 2008
    Posts
    7

    Exclamation Re: Applet notinited

    This is the output in Java Console with trace level set to 5:

    Trace level set to 5: all ... completed.
    basic: Added progress listener: sun.plugin.util.GrayBoxPainter$GrayBoxProgressListener@91cee
    network: Cache entry not found [url: http://localhost:8080/AppletApplication/ButtonMoveApplet.class, version: null]
    network: Connecting http://localhost:8080/AppletApplication/ButtonMoveApplet.class with proxy=DIRECT
    network: Connecting http://localhost:8080/ with proxy=DIRECT
    network: Connecting http://localhost:8080/AppletApplication/ButtonMoveApplet.class with cookie "JSESSIONID=233A84F908CDE6BF4F6699362106CBA4"
    network: Cache entry not found [url: http://localhost:8080/AppletApplication/ButtonMoveApplet.class, version: null]
    network: Connecting http://localhost:8080/AppletApplication/ButtonMoveApplet.class with proxy=DIRECT
    network: Connecting http://localhost:8080/AppletApplication/ButtonMoveApplet.class with cookie "JSESSIONID=233A84F908CDE6BF4F6699362106CBA4"
    basic: load: class ButtonMoveApplet not found.
    load: class ButtonMoveApplet not found.
    java.lang.ClassNotFoundException: ButtonMoveApplet
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.io.IOException: open HTTP connection failed:http://localhost:8080/AppletApplication/ButtonMoveApplet.class
    at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    ... 7 more
    Exception: java.lang.ClassNotFoundException: ButtonMoveApplet

  5. #5
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,858

    Re: Applet notinited

    Where is the class file located? Is it in the AppletApplication folder? Does the browser issue a HTTP GET for the Appln.jar file? I don't see it in your trace. Is your HTML correct?
    Does it work If you create a static HTML file and place it in the same folder with the jar file?
    Norm

  6. #6
    Join Date
    Nov 2008
    Posts
    7

    Re: Applet notinited

    Quote Originally Posted by Norm
    Where is the class file located? Is it in the AppletApplication folder? Does the browser issue a HTTP GET for the Appln.jar file? I don't see it in your trace. Is your HTML correct?
    Does it work If you create a static HTML file and place it in the same folder with the jar file?
    My applet program is in the package com.wipro.applets. I have JARed this applet in a JAR called Appln.jar.

    I dont understand what you mean by this --> Does the browser issue a HTTP GET for the Appln.jar file?

  7. #7
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,858

    Re: Applet notinited

    "applet program is in the package com.wipro.applets"
    When you have an applet in a package, then the code= attribute(class= in <APPLET) must specify the package path. If you'd tested the HTML as a static file you would have seen this.

    Does it work If you create a static HTML file and place it in the same folder with the jar file and open the HTML file in a browser locally, no server?

    Where is the Appln.jar located on the server? When the browser reads the HTML from the server, it then issues HTTP GETs for the files referenced in the HTML. It will look for the .class file and for the .jar file using HTTP GETs. If the file is not at the address in the HTTP GET, the server will return a 404 and the browser will say the class is not found.
    If you can see where the browser is asking the server to look and that is not where your jar file is, then you should move the jar file there.
    Norm

  8. #8
    Join Date
    Feb 2008
    Posts
    966

    Re: Applet notinited

    Quote Originally Posted by redhunt
    My applet program is in the package com.wipro.applets. I have JARed this applet in a JAR called Appln.jar.

    I dont understand what you mean by this --> Does the browser issue a HTTP GET for the Appln.jar file?
    You cannot simply place a JAR file in any directory/package and expect the program to pick it up. You have to place it somewhere in the classpath for your project that the build (Maven / Ant / What ever) to pick up. Try placing it where all of your other JAR files are instead of in sub folders.

  9. #9
    Join Date
    Nov 2008
    Posts
    7

    Re: Applet notinited

    I had written two simple static htmls. One calls the class without JAR files and its working.
    <applet code="ButtonMoveApplet" codebase="." width="400" height="400">

    Other calls the JAR to access the class:
    <applet code="ButtonMoveApplet" codebase="." archive="Appln.jar" width="400" height="400">
    It is also working.

    Following also works:
    <applet code="ButtonMoveApplet" codebase="com/wipro/applets" width="400" height="400">
    Below one works only if the JAR is also in the same folder as the class otherwise browser is not picking up the JAR.
    <applet code="ButtonMoveApplet" codebase="com/wipro/applets" archive="Appln.jar" width="400" height="400">

  10. #10
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,858

    Re: Applet notinited

    "program is in the package com.wipro.applets" ie program starts with: package com.wipro.applets;
    Not sure how the above HTML works if your applet is in the package shown.
    I thought that the attribute: code=com.wipro.applets.ButtonMoveApplet would have to be used.
    When you use the HTML with the jar file, is there a path to the class file(com.wipro.applets) visible to the browser? IE where is the browser getting the class file, from the jar or from the folder?

    So if all those HTML pages work, and the browser is using the jar file to get the class, where is the server looking for the jar file when the browser asks for the HTML and then asks for the jar file?
    If you can see where the browser is asking the server to look and that is not where your jar file is, then you should move the jar file there.
    Norm

  11. #11
    Join Date
    Nov 2008
    Posts
    7

    Re: Applet notinited

    program is in the package com.wipro.applets" ie program starts with: package com.wipro.applets;
    Not sure how the above HTML works if your applet is in the package shown.
    I thought that the attribute: code=com.wipro.applets.ButtonMoveApplet would have to be used.
    Quote Originally Posted by Norm View Post
    "When you use the HTML with the jar file, is there a path to the class file(com.wipro.applets) visible to the browser? IE where is the browser getting the class file, from the jar or from the folder?

    So if all those HTML pages work, and the browser is using the jar file to get the class, where is the server looking for the jar file when the browser asks for the HTML and then asks for the jar file?
    When the JAR contains the class in a package structure, browser is not picking it up. How to find where the server is looking for the clas file.?

  12. #12
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,858

    Re: Applet notinited

    Can you use a static HTML and applet from the server? Does that work?
    Then you need to find out where the server is looking for the class or jar file.
    Some servers have trace logs that will show what HTTP GETs were sent to it by a browser.
    Does yours have that? It could show the path that the browser is using to ask for the jar file.
    Otherwise, you will have to try moving the jar file to ALL the different folders it might look in until you find the folder. Several ways to do this. Copy the jar file to LOTS of folders until the server finds it. Then erase them one at a time and test again. Continue until the server doesn't find it, then you'll know that the last one erased was where the server looks.
    Norm

  13. #13
    Join Date
    Feb 2008
    Posts
    966

    Re: Applet notinited

    Norm, he should be able to check the environment (env) to see what paths exist for Java and place the JAR file in there right?

  14. #14
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,858

    Re: Applet notinited

    Depends on the server. I think his problem is that the server is NOT finding the class/jar file.
    If he is using a browser to ask for a jsp page, that page is returning an HTML page with an <APPLET tag(or simiilar) to the browser. The browser then asks the server for the class/jar file referenced in that tag.
    That's the request I'd like to see the path to the file for. But a server can translate that path to somewhere else, hence my shotgun approach to putting jar files everywhere until the server finds one. Then removing them one by one to find which one is being used.

    For example when I load an HTML page (http://127.0.0.1:8080/Testing/AppletReader.html) into my browser and that HTML has an archive= attribute, my server sees the following to HTTP GETs:
    GET /Testing/AppletReader.html HTTP/1.1
    GET /Testing/AppletReader.jar HTTP/1.1

    The <APPLET tag:
    <APPLET CODE=AppletReader Archive=AppletReader.jar WIDTH=300 HEIGHT=300>
    Last edited by Norm; November 6th, 2008 at 11:43 AM.
    Norm

  15. #15
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Applet notinited

    Have I missed something? What's wrong with using the applet 'archive' attribute?
    Applet Parameters.

    The real technology -behind all our other technologies- is language. It actually creates the world our consciousness lives in...
    A. Codrescu
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Page 1 of 2 12 LastLast

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)