Passing String value Java Parameters into Javascript - Java Scripting

Java examples for Scripting:Bindings

Description

Passing String value Java Parameters into Javascript

Demo Code

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*/

}

Result


Related Tutorials