java后台调用js方法
public String start() throws ScriptException { ScriptEngineManager scriptManager = new ScriptEngineManager(); ScriptEngine js = scriptManager.getEngineByExtension("js"); String fun = "function A() {alert(\"123\");}"; js.eval(fun); return "success"; }
public String start() throws ScriptException { ScriptEngineManager scriptManager = new ScriptEngineManager(); ScriptEngine js = scriptManager.getEngineByExtension("js"); String fun = "function A() {println(\"123\");}\nA();"; js.eval(fun); return "success"; }
[解决办法]
楼上正解 ,你只是定义了方法 没有调用肯定没结果,而且后台传过去 alert没用 只能Print