Java examples for Scripting:Bindings
Passing String value Java Parameters into Javascript
import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.SimpleBindings; public class Main { public static void main(String[] args) throws Exception { String myJavaString = "test"; ScriptEngineManager sem = new ScriptEngineManager(); ScriptEngine nashorn = sem.getEngineByName("nashorn"); SimpleBindings simpleBindings = new SimpleBindings(); simpleBindings.put("myString", myJavaString); nashorn.eval("print (myString)", simpleBindings); }/* w w w . j av a 2 s . co m*/ }