On Sun, 25 May 2008 02:46:42 -0700, JCD wrote:
I'd like to get the result of a javascript method (executed in a web
browser) in a java application. Is it possible and how can I do it?
Yes it is possible. Take a look at the javax.script package (which exists
since Java 6).
Here is an example, executing a JS method called "myFunction" :
public static void main(String[] args) {
try {
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("JavaScript");
String myJSCode = new StringBuffer()
.append("function myFunction() {")
.append("return (4 + 5);")
.append("}")
.append("myFunction();").toString();
System.out.println(engine.eval(myJSCode));
} catch (ScriptException ex) {
ex.printStackTrace();
}
}
Ah. That is also a possibility.
could also be embedded in (or fetched by) Java.
of JS can actually interact using Java as glue.