Javascript using Java methods

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • annie

    Javascript using Java methods

    Hi all.

    Can Java classes/objects be used from within the javascript code on the
    HTML page?
    I.e., can I call a Java method from the javascript function?
    Thanks in advance

    Anna

  • Martin Honnen

    #2
    Re: Javascript using Java methods



    annie wrote:

    [color=blue]
    > Can Java classes/objects be used from within the javascript code on the
    > HTML page?
    > I.e., can I call a Java method from the javascript function?[/color]

    If you embed a Java applet e.g.
    <applet name="appletNam e" code="applet.cl ass"></applet>
    then in some browsers you can call the public methods of that applet e.g.
    document.applet s.appletName.me thodName();
    It however depends on the browser and the used Java virtual machine
    whether that works, if you use the Sun JRE for Java and browsers like
    Mozilla 1.4 or later, Opera 7, IE 5/6 on Windows then it works, IE on
    Win with the MS Java VM should also work. I think it doesn't work with
    MSIE/Mac while the latest Safari versions are reported to support
    JavaScript-->Java applet communication.

    In Mozilla and in Opera with the Sun JRE you can also directly script
    Java, I have only tested that on Windows, but there you can do e.g.
    var javaDate = new java.util.Date( );
    but that doesn't work with MSIE, whatever Java (Sun or MS) you use.

    --

    Martin Honnen

    Comment

    • Laurent Bugnion

      #3
      Re: Javascript using Java methods

      Hi,

      annie wrote:
      [color=blue]
      > Hi all.
      >
      > Can Java classes/objects be used from within the javascript code on the
      > HTML page?
      > I.e., can I call a Java method from the javascript function?
      > Thanks in advance
      >
      > Anna[/color]

      In Mozilla, you can.

      Example:

      netscape.securi ty.PrivilegeMan ager.enablePriv ilege(
      "UniversalFileR ead" );

      var flCheck = new java.io.File( strFullPath );
      bFileExists = flCheck.exists( );

      Or:

      netscape.securi ty.PrivilegeMan ager.enablePriv ilege(
      "UniversalFileW rite" );
      var fsOutput = new java.io.FileOut putStream( strFullPath );
      var flOutput = new java.io.DataOut putStream( fsOutput );

      flOutput.writeB ytes( strContent );

      flOutput.flush( );
      fsOutput.close( );


      On other browsers, one solution is to pack your Java classes in an
      applet and to use LiveConnect (if supported) to access the applet's
      public classes.

      See


      Laurent
      --
      Laurent Bugnion, GalaSoft
      Software engineering: http://www.galasoft-LB.ch
      Private/Malaysia: http://mypage.bluewin.ch/lbugnion
      Support children in Calcutta: http://www.calcutta-espoir.ch

      Comment

      Working...