This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 3476

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: 60048
    
  65

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]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Calling Java method from Javascript
 
Similar Threads
jsp and javascript
Can I Iterate through an Arraylist inside a javascript funtion?
Href with onClick
Calling Javascript function from Java Code
java jar Question