Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Javascript using Java methods

Reply
Thread Tools

Javascript using Java methods

 
 
annie
Guest
Posts: n/a
 
      12-21-2004
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

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      12-21-2004


annie wrote:


> 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?


If you embed a Java applet e.g.
<applet name="appletName" code="applet.class"></applet>
then in some browsers you can call the public methods of that applet e.g.
document.applets.appletName.methodName();
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
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
Laurent Bugnion
Guest
Posts: n/a
 
      12-21-2004
Hi,

annie wrote:

> 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


In Mozilla, you can.

Example:

netscape.security.PrivilegeManager.enablePrivilege (
"UniversalFileRead" );

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

Or:

netscape.security.PrivilegeManager.enablePrivilege (
"UniversalFileWrite" );
var fsOutput = new java.io.FileOutputStream( strFullPath );
var flOutput = new java.io.DataOutputStream( fsOutput );

flOutput.writeBytes( 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
http://www.galasoft-lb.ch/myjavascri...LiveConnect102

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using JNI to Call C++ Methods from Java Using NetBeans IDE 7.1.2 clusardi2k@aol.com Java 0 06-14-2012 07:17 PM
Is there a way to find the class methods of a class, just like'methods' finds the instance methods? Kenneth McDonald Ruby 5 09-26-2008 03:09 PM
Using object methods of first module in methods of second module Nikita Petrov Ruby 2 04-06-2008 08:49 PM
JavaScript calling java methods ezhilvel@gmail.com Java 3 03-08-2008 12:15 AM
Why Petshop Changed all static methods to instance methods when upgrading from version 3.0 to version 3.1? Neo ASP .Net 1 01-07-2005 01:46 AM



Advertisments