我正在尝试从 java 类调用 javascript 函数,但出现以下错误:
-Could not find method sun.misc.Service.installedProviders, referenced from method javax.script.ScriptEngineManager.initEngines
-Could not find method sun.misc.Service.providers, referenced from method javax.script.ScriptEngineManager.initEngines
-Could not find method sun.misc.Service.installedProviders, referenced from method javax.script.ScriptEngineManager.initEngines
-java.lang.VerifyError: javax.script.ScriptEngineManager
这里的代码:
public void sendResult(){
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("js");
String script = "function send() {"+"var id_result = window.MyPGP.getResult();"+
"document.getElementById('id_result').value = id_result;"+"console.log(\"change the box value\");";
try {
engine.eval(script);
Invocable invocableEngine = (Invocable) engine;
invocableEngine.invokeFunction("send");
} catch (ScriptException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
我真正想做的是,当支付完成时,这个函数在这个类的其他方法中被调用来得到支付的结果,并打印在主html的一个框中。