In my Java Script , I want to call a java m开发者_JS百科ethod . Is it possible to call a java method by js w/o using ajax?
use Direct Web Remoting for your Javascript to Java Interaction
DWR is a Java library that enables Java on the server and JavaScript in a browser to interact and call each other as simply as possible.
DWR is Easy Ajax for Java
Examples
EDIT: as Daniel said u can use Rhino interpreter or run an applet to do the call
If you're running from a browser then there is a sandbox which has a security policy that defines and disallows calling Java Methods directly from browser.
If you are running in Rhino javascript, which is a JS engine implemented in the JVM, then yes.
If you're running a browser, the answer is almost certainly no, at least directly. You could write a Java applet to run in the browser, and you might be able to call methods in it from JavaScript.
You can't directly call Java method in javascript irrespective of Ajax present or not. Javascript is at client side.
If you are using JSP, then you can call using scriplets
<script>
....
if(somecondition) {
<%
ClassXXX.xXXX();
%>
}
....
</script>
精彩评论