aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Calling Java method from Javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Calling Java method from Javascript" Watch "Calling Java method from Javascript" New topic
Author

Calling Java method from Javascript

Jayanth Mathavan
Greenhorn

Joined: Nov 10, 2005
Posts: 16
Hi,
I want to call a method of a standalone Java code from within a Javascript. Below is the way we can call a static method in a Java code.

var x = Packages.MyClass.add_method(5,10);

add_method() is a static method in MyClass..

Suppose I want to call a non-static method belonging to the class, how to do it? Can someone please help me out? am not using applets.

Thanks,
Jayanth Mathavan.
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

Below is the way we can call a static method in a Java code.

var x = Packages.MyClass.add_method(5,10);

Do you use var to declare a variable in Java?
Assuming that you are developing a web application, I suggest you use DWR to call server side Java code.
Jayanth Mathavan
Greenhorn

Joined: Nov 10, 2005
Posts: 16
Hi,

No, I didn't use var for declaring a variable in Java. I can even use as shown below,

Packages.MyClass.add_method(5,10);

This is not a web application. This Javascript is used in one of the modules in a tool called Kettle. So I don't think it will be possible to use DWR.

Thanks,
Jayanth.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61769
    
  67

Originally posted by Jayanth Mathavan:
This is not a web application. This Javascript is used in one of the modules in a tool called Kettle. So I don't think it will be possible to use DWR.
WOuld this not have been important information to include with the original post? Please explain your environment, most people will assume that you are working in a browser when you post a question to an HTML forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling Java method from Javascript