Re: How to get the result of a javascript method in a java
application?
On 25 mai, 12:57, Vivien Barousse <barousse.viv...@gmail.com> wrote:
On Sun, 25 May 2008 02:46:42 -0700, JCD wrote:
Hello.
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?
thank you.
Hi.
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();
}
}
Hope this helps,
Vivien Barousse
I've created a google map in an html page wich is displayed in the web
browser. When I drag the map, I want to get the coordinates of the new
center of the map in a java application. The Javascript method is
map.getCenter() and I need the result in my application.
Do you think javax.script can help?