about script engine on jdk 6 is mozilla rhino

http://java.sun.com/developer/technicalArticles/J2SE/Desktop/scripting/

reference:

here is an example

            String promotion_price = null;
            String json_string="var shopVipData={\"msg\":\"\",promo:[{\"type\":\"普通会员\",\"price\":\"45.75\"},{\"type\":\"高级会员\",\"price\":\"45.71\"},{\"type\":\"VIP会员\",\"price\":\"45.34\"},{\"type\":\"至尊VIP\",\"price\":\"44.88\"}]};";
            json_string=http_response;
            logger.debug(json_string);
            String js_string="var price;for(var i=0;i<=shopVipData.promo.length-1;i++){if(shopVipData.promo[i].type=='普通会员'){price=shopVipData.promo[i].price;}}";

            ScriptEngineManager manager = new ScriptEngineManager();
            ScriptEngine engine = manager.getEngineByName("JavaScript");
            Compilable compilable = (Compilable) engine;
            CompiledScript script = null;
            Bindings binds = engine.createBindings();
            try {
                script = compilable.compile(json_string+js_string);
                script.eval(binds);
                promotion_price=binds.get("price").toString();
                logger.debug("=-----------------------------");
               
            } catch (ScriptException e) {
                e.printStackTrace();
            }   

原文地址:https://www.cnblogs.com/lexus/p/2336401.html