problem with JSobject throwing exception

Discussion in 'Java' started by naveen, Mar 21, 2006.

  1. naveen

    naveen Guest

    hai all
    I am working in a project in whihc i need to modify the dom of a
    webpage and reload the page with modified dom.
    so for this i thought of working with JSObject and with applet
    commnication
    As a sample here is the code i am working i am getting the exception as
    fallows
    please help me out how to modify it

    HTML part
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <applet id="myapplet" width="300" height="500" code ="jsobject.class"
    codebase=".">
    <param name="InitialMode" value="Normal">
    </applet>
    <script>
    function f()
    {
    alert ("calling this frunction from java script via java ");
    }
    </script>

    <BODY>
    <input type="button" value ="from js to java"
    onclick="document.myapplet.doitt()">
    </BODY>
    </HTML>


    JAVA PART


    import java.applet.*;
    import netscape.javascript.*;
    public class jsobject extends Applet {
    private static final long serialVersionUID = 1L;

    public void init()
    {
    JSObject win = JSObject.getWindow(this);
    JSObject doc = (JSObject) win.getMember("document");
    JSObject loc = (JSObject) doc.getMember("location");

    String s = (String) loc.getMember("href"); //
    document.location.href
    win.call("f", null); ; }
    }


    Here is the exception

    netscape.javascript.JSException
    at netscape.javascript.JSObject.getWindow(JSObject.java:144)
    at jsobject.init(jsobject.java:15)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)


    I have adedd the folder for netscape.javascript from jdk
    So how can i modify this error
    thanking you in advance
    nimbooin
     
    naveen, Mar 21, 2006
    #1
    1. Advertising

  2. naveen

    Guest

    > hai all

    'hai' is just a 'kewl' way to say 'hi' or 'hello', I would recommend
    either of the latter.

    > I am working in a project in whihc i need to modify the dom of a
    > webpage and reload the page with modified dom.

    ....
    > please help me out how to modify it
    >
    > HTML part
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    > <HTML>
    > <applet id="myapplet" width="300" height="500" code ="jsobject.class"
    > codebase=".">


    This represent invalid HTML, an applet element is only valid when
    enclosed
    by a 'body' element. You should make a static HTML page of all pages
    that are created using JS and check them in the HTML validator at W3C.
    ....
    > import java.applet.*;
    > import netscape.javascript.*;
    > public class jsobject extends Applet {
    > private static final long serialVersionUID = 1L;
    >
    >
    > public void init()
    > {


    try {

    > JSObject win = JSObject.getWindow(this);
    > JSObject doc = (JSObject) win.getMember("document");
    > JSObject loc = (JSObject) doc.getMember("location");
    >
    >
    > String s = (String) loc.getMember("href"); //
    > document.location.href
    > win.call("f", null); ;


    } catch(JSException jse) {
    jse.printStackTrace();
    } catch (Exception e) {
    e.printStackTrace();
    }


    > }

    ....

    > So how can i modify this error


    1. Validate both the HTML this all occurs in, as well as any
    HTML you intend to write using JS.
    2. Catch those exceptions (as shown above, beginning example)
    so that you as the programmer regain control and can then DO
    something about them (exactly what to do, is the next question)
    3. Post the URL of your current broken page - if it is not uploaded,
    upload it. (There were a dozen more questions I could ask, but they
    are all answered by the looking at your web page.)
    4. Study this document carefully..
    <http://java.sun.com/products/plugin/1.3/docs/jsobject.html>

    HTH

    Andrew T.
     
    , Mar 21, 2006
    #2
    1. Advertising

  3. naveen

    Roedy Green Guest

    On 21 Mar 2006 14:37:14 -0800, wrote, quoted or
    indirectly quoted someone who said :

    >> HTML part
    >> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    >> <HTML>
    >> <applet id="myapplet" width="300" height="500" code ="jsobject.class"
    >> codebase=".">

    >
    >This represent invalid HTML, an applet element is only valid when
    >enclosed


    Be lazy and validate your HTML and CSS before bashing your head trying
    to figure out why it does not work.

    See http://mindprod.com/jgloss/htmlvalidator.html
    http://mindprod.com/jgloss/css.html
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
     
    Roedy Green, Mar 21, 2006
    #3
  4. naveen

    naveen Guest

    hi
    Thank you for the replies, the problem still persists, and i can get
    the resutls when i open the html page containting the applet. But
    from the java part i am getting the exception. I am using eclispe IDE
    I have adedd jaws.jar,plugin.jar and java40.jar libraries also. It was
    still not identifying the path to jsobject class.
    Here is the error
    exception caught
    netscape.javascript.JSException
    at netscape.javascript.JSObject.getWindow(JSObject.java:144)
    at MyApplet.init(MyApplet.java:15)
    at sun.applet.AppletPanel.run(AppletPanel.java:378)
    at java.lang.Thread.run(Thread.java:595)

    I am not getting what exact problem is i have tried the try catch
    blocks also
    please help me out
    thanking you
     
    naveen, Mar 22, 2006
    #4
  5. naveen

    Guest

    naveen wrote:
    > hi
    > Thank you for the replies, the problem still persists,


    So where's your URL? (point 3 in my first reply)

    > please help me out


    Please 'help yourself out' by following the instructions I give
    in attempts to resolve the problem.
     
    , Apr 19, 2006
    #5
  6. naveen

    Abaddon

    Joined:
    Nov 13, 2008
    Messages:
    1
    Hi,
    I've got the same error :(
    Exception netscape.javascript.JSObject.getWindow(JSObject.java:144) appears while I execute my applet from eclipse IDE.
    In case running my applet from browser it works fine.

    Could you please provide me with some solution how to solve this issue. It's very important to run this applet from eclipse.

    Thanks!
     
    Abaddon, Nov 13, 2008
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pratul Chatterjee

    JSObject leaks on MSJVM

    Pratul Chatterjee, Jun 14, 2004, in forum: Java
    Replies:
    2
    Views:
    1,340
    Pratul Chatterjee
    Jun 15, 2004
  2. Minh Tran-Le
    Replies:
    0
    Views:
    442
    Minh Tran-Le
    Dec 2, 2004
  3. Replies:
    1
    Views:
    486
    Andrew Thompson
    Oct 31, 2005
  4. Richard Maher
    Replies:
    18
    Views:
    2,299
    Richard Maher
    Mar 27, 2009
  5. Richard Maher

    Daniel Pitts on JSObject and FireFox

    Richard Maher, Mar 20, 2009, in forum: Java
    Replies:
    6
    Views:
    571
    Richard Maher
    Mar 21, 2009
Loading...

Share This Page