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.sayHello("hermit");
10 } catch (Exception se) {
11 se.printStackTrace();
12 }
13 }
14
15
16
17 public void sayHello(String name) {
18 ScriptEngineManager sem = new ScriptEngineManager();
19 ScriptEngine jsEngine = sem.getEngineByName("js");
20 try {
21 jsEngine.eval("print('hello " + name + "')");
22 } catch (ScriptException e) {
23 e.printStackTrace();
24 }
25 }
26
27
28 }
输出:
hello hermit
posted on 2006-12-26 14:03
交口称赞 阅读(998)
评论(0) 编辑 收藏 所属分类:
Java6