浏览 1841 次
锁定老帖子 主题:web-harvest基础学习一
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-10-15
<var-def name="birthday">2/10/2008</var-def> <var-def name="web_harvest_day_variable"> <script return="nameDay.toUpperCase()"><![CDATA[ tokenizer = new StringTokenizer(birthday.toString(),"./-\\"); day = Integer.parseInt(tokenizer.nextToken()); month = Integer.parseInt(tokenizer.nextToken()); year = Integer.parseInt(tokenizer.nextToken()); Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_MONTH,day); cal.set(Calendar.MONTH,month); cal.set(Calendar.YEAR,year); switch(cal.get(Calendar.DAY_OF_WEEK)) { case 0 : nameDay = birthday+" Sunday"; break; case 1 : nameDay = birthday+" Monday"; break; case 2 : nameDay = birthday+" Tuesday"; break; case 3 : nameDay = birthday+" Wendsday"; break; case 4 : nameDay = birthday+" Thursday"; break; case 5 : nameDay = birthday+" Friday"; break; default: nameDay = birthday+" Saturday"; break; } ]]></script> </var-def> <file action="write" path="day.txt"> <template>The day when you were born was ${nameDay}.</template> <var name="web_harvest_day_variable"/> </file> 例子在<script>标签里面用了一种叫[url= http://www.beanshell.org/home.html]beanshell[/url]的轻量级JAVA脚本语言, 在该脚本里面可以调用JAVA的各种基本的函数,使用起来比较灵活,但是有一点要注意的 是,在其里面不能直接调用平时JAVA里面的各种函数,而是要先进行类型的转换后才能进行 调用,比如上面和下面的例子中就是先进行转换再调用的: <var-def name="hello">Hello to the world!</var-def> <!-- 在script里面可以用外面定义的变量,但不能直接就拿来用,而是要先进行转化,比如说String要用到toString() 其它转换函数还有: byte[] toBinary() boolean toBoolean() int toInt() long toLong() double toDouble() Object[] toArray() java.util.List toList() Object getWrappedObject() --> <var-def name="test_str"> <script return="temp.toUpperCase()"><![CDATA[ temp = hello.toString(); ]]></script> </var-def> <file action="write" path="script_1.txt"> <var name="test_str"/> </file> 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |