Reputation: 173
I am new in JavaScript. I want to know how to call a simple method in Java file from JavaScript program. Could you please give me a simple example as well?
Thank you
Upvotes: 1
Views: 2170
Reputation: 5519
Javascript will not be able to access server side java code directly. It will need to make an ajax call to access a method or make a http call.
If you have applets you will be able to access the applet java code.
See example here http://download.oracle.com/javase/1.5.0/docs/guide/plugin/developer_guide/js_java.html
Upvotes: 5
Reputation: 5150
When you say "java file" I presume you mean a Java applet. In that case, say you have this applet code on your page:
<applet id="myapplet" class="MyApplet.class" ... />
If you wanted to call the helloWorld() method in that applet, you simply need to do this:
<script type="text/javascript>
document.getElementById['myapplet'].helloWorld();
</script>
Upvotes: 3