1 import javax.script.ScriptEngine;
2 import javax.script.ScriptEngineManager;
3 import javax.script.ScriptException;
4
5 public class JavaScriptEngineTest {
6 public static void main(String[] args) {
7 try {
8 JavaScriptEngineTest test = new JavaScriptEngineTest();
9 test.testObject("a", 7);
10 } catch (Exception se) {
11 se.printStackTrace();
12 }
13 }
14
15 public void testObject(String key, int value) {
16 ScriptEngineManager manager = new ScriptEngineManager();
17 ScriptEngine engine = manager.getEngineByName("js");
18 engine.put(key, value);
19 try {
20 engine.eval("print(" + key + "+1)");
21 } catch (ScriptException e) {
22 e.printStackTrace();
23 }
24 }
25 }
输出:
8
posted on 2006-12-26 14:07
交口称赞 阅读(971)
评论(0) 编辑 收藏 所属分类:
Java6