Options to call Java method from Javascript -
what various options call "specific" java method javascript , have callback, etc?
e.g. 1 know using dwr..but wanted know if there other libraries can used or if can done ajax itself..
what recommended approach?
put simply, possible exception of java applet running in same page context javascript, there no way javascript directly call java method, or vice-versa. dwr isn't calling java methods directly javascript, it's sending ajax request server , using own intermediate layer instrument request , response processing such looks if calling java methods.
but anyways, typical approach getting javascript code in client , java code on server talk 1 define api on server exposed client. client can make requests (using ajax or whatever other mechanism prefer) using exposed api. client isn't calling java methods directly, instead it's sending request given url on server, gets mapped bit of java code. popular javascript frameworks provide convenience methods simplifying ajax request handling , callbacks.
if reason want functionality equivalent being able call arbitrary method in arbitrary class , have result returned you, define api method takes parameters class name , method name , uses reflection perform method invocation. close server-side portion of dwr doing.
Comments
Post a Comment