- Create instance of type ScriptEngineManager
- Get JavaScript engine instance by called getEngineByName method
- Us e the eval method to evaluate your javascript code
Sample Code
=================================================
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("js");
engine.eval("var x = 5;var y = x + 2");
System.out.println(engine.eval("y"));
=================================================
No comments:
Post a Comment