package com.utils;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
/**
* @author wangbingchen
* java 实现 js 方法调用
* @since 2022-05-12
**/
public class ScriptUtil {
private static ScriptEngine js = new ScriptEngineManager().getEngineByExtension("js");
public static String escape(String text) {
return eval("escape('"+text+"')");
}
private static String eval(String text) {
try {
Object eval = js.eval(text);
return eval.toString();
} catch (ScriptException e) {
e.printStackTrace();
}
return null;
}
}