日期:2014-05-20 浏览次数:20642 次
import javax.script.*; public class TestScript { public static void main(String[] args) throws Exception { String str = "(a >= 0 && a <= 5)"; ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); engine.put("a",4); Object result = engine.eval(str); System.out.println("结果类型:" + result.getClass().getName() + ",计算结果:" + result); } }
------解决方案--------------------
楼上的厉害,.......