Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

ScriptEngine: Exemple d’utilisation de la classe ‘Bindings’


{filelink=938}

 
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.Bindings;
import javax.script.ScriptContext;
 
public class ScriptBindings {
 
  public static void main(String[] args) throws Exception {
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByName("js");
    engine.put("a", 3);
    engine.put("b", 14);
    engine.put("c", 8);
 
    Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
    Object a = bindings.get("a");
    Object b = bindings.get("b");
    Object c = bindings.get("c");
    System.out.println("Valeur de a = " + a);
    System.out.println("Valeur de b = " + b);
    System.out.println("Valeur de c = " + c);
 
    Object resultat = engine.eval("x = (a + b)*c;");
    System.out.println("x = (a + b)*c = " + resultat);
  }
}

A Voir sur le même Sujet:

  • exemple execution javascript avec scriptengine
  • java Simple Bindings example script engine
  • javax scriptengine
  • scriptengine import class
  • exemple scriptengine
  • scriptenginemanager exemple
  • scriptenginemanager java examples francais