package com.huike.hidp.system.customform.service;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import org.junit.Test;
import com.sun.script.javascript.RhinoScriptEngine;
public class MethodTest {
@Test
public void testInvokeScriptMethod() throws Exception{
ScriptEngine engine = new RhinoScriptEngine();
this.invokeScriptMethod(engine);
}
public void invokeScriptMethod(ScriptEngine engine)
throws Exception {
String script = "function helloFunction(name) { return 'Hello everybody,' + name;}";
engine.eval(script);
Invocable inv = (Invocable) engine;
String res = (String) inv.invokeFunction("helloFunction", "Scripting");
System.out.println("res:" + res);
}
}
时间: 2025-01-02 21:16:20