javax.script pass to javascript a Java method to use as a callback -
i'm using javax.script embed javascript code java method.
in project javascript takes care send asynchronous http request through websocket. once response received need execute callback function.
i invoke method written in java callback.
in documentation here: http://docs.oracle.com/javase/6/docs/technotes/guides/scripting/programmer_guide/ explained how implement java methods in javascript interface, not how invoke java methods form javascript.
thanks
not sure if looking for, here code sample supplies java object callback javascript code call on callback later:
public class jscallback{ public static void main(string[] args) throws exception{ scriptenginemanager factory = new scriptenginemanager(); scriptengine engine = factory.getenginebyname("javascript"); engine.put("cb", new jscallback()); engine.eval("println('doing in javascript here first');" + "cb.apply('bar');"); } public void apply(string s){ system.out.println("back in java code here: " + s); } }
Comments
Post a Comment