Error Handling with java applets


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Error Handling with java applets

Hybrid View

  1. #1
    Join Date
    May 2005
    Posts
    2

    Error Handling with java applets

    Im running my webpage that opens a java applet running on a server (ivista streaming video) and I have it all working but I want to see if anyone can tell me if there is any way to handle the error that comes up when the server that runs the applet isnt running. Like some kind of error code in the html of my webpage that if the error comes up it the user would be redirected to another page. When the server isnt running, the webpage opens with the java applet box, the java logo sunburst or whatever it is goes round and round and then ends up with the red X in the upper left corner and the status line of the browser at the bottom says "applet failed to load". Sorry, Im complete dummy about how these applets or javascripts work but thought maybe someone here could direct me toward a way to solve the problem, Ive googled for 2 days trying to find a way and cant. ALOHA kh6gmp

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    From the top of my head; would it work if you had a javascript that tested for the
    existence of a public (dummy) method in the applet a spcific time after page load.

    You know, the name specified in the applet tag can be used by javascript to
    access the applets public methods. If there is nothing there the javascipt could
    load an alternate page.
    eschew obfuscation

  3. #3
    Join Date
    May 2005
    Posts
    2
    Thanks Sjalle. Well, Im game to try anything but wonder if you could write me a script that would let me try what you suggested. I would have no idea where to start, thats why I came to this forum. I have the server running now so if you were to go to my page you could view the applet by looking at the source code and if you wouldnt mind, writing me up a little script that would do as you suggested. If you'd do that the URL to go to my page is http://home.hawaii.rr.com/kh6gmp/index9.htm What I want it to do is go to an alternate page if the server isnt running - right now if the server isnt running you get a box that says the connection was refused at 66.8.184.220:80 Thanks ALOHA kh6gmp

  4. #4
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    Ok, its saturday night here now, but Ill bundle up the "how-to-boil-an-egg" version
    and post it here tomorrow. Programmatically its very simple, I recon a total of
    10 programming lines max.... that is if it works I've never tried
    this before...
    Last edited by sjalle; 05-07-2005 at 02:47 PM.
    eschew obfuscation

  5. #5
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560

    This works, sortof...

    ...and it requires no changes to the applet code. However, it relies on
    the error that occurs when the javascript tries to invoke a basic
    applet function (getAppletInfo()) of an applet that is not there. The
    error is trapped and the alternate url is shown. But if the user has a
    setup that pops up a javascript error dialog (it can be surpressed) when
    that happends there is nothing this code can do about that. Even so,
    after the used has clicked OK in that dialog, the new page will show:

    Here is my HTML test setup, I've tried it with my LostApplet like: when the
    applet was on the server, and when it wasn't. In the last case it switched
    to the new page smoothly (I've surpressed the javascript error message in
    IE).

    Code:
    <html><head><title>
    LostApplet Test Page
    </title>
    <SCRIPT language="JavaScript1.2" type="text/javascript">
    <!--
    /***************************************************************
    * Rudimentary setup for switching to other URL when the applet is
    * not available (server down).
    * NOTE: this setup only makes sense if the html and the applet
    * are on different servers.
    * ***************************************************************
    */
    
    /**
    *
    * Error trapping
    */
    onerror = function () {
      showOtherURL();
    }
    /**
    * Set time to wait for applet
    */
    function startTimer() {
      setTimeout("checkApplet()",5000); // 5000=5 seconds, probably too little
    }
    /**
    * Invoke a basic applet function, will generate error if applet not
    * available
    */
    function checkApplet() {
      s=LostApplet.getAppletInfo();
    }
    /**
    * Show the other url, NOTE: last parameter string in
    * the open() call can have NO SPACES.  The space that can be seen
    * here is added during upload to the forum :(
    */
    function showOtherURL() {
      NewWindow=window.open( "http://www.hyperdictionary.com","_self",
        "toolbar=0,location=1,status=1,menubar=1,scrollbars=1,resizable=1,width=820,height=700")
    }
    // -->
    </SCRIPT>
    </head>
    <body onLoad="startTimer();">
    The lost applet (?)<br>
    <applet
      codebase = "."
      code     = "stubs6.LostApplet.class"
      name     = "LostApplet"
      width    = "400"
      height   = "300"
      hspace   = "0"
      vspace   = "0"
      align    = "middle"
    >
    </applet><br>
    </body>
    </html>
    Last edited by sjalle; 05-08-2005 at 10:39 AM.
    eschew obfuscation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center