我用的是velocity1.7版本,要在web使用velocity引擎,必须把它的velocity-1.7.jar包放在tomcat(整个tomcat的多个项目可以共用)或者webroot下的web-inf下(只有自己可以用);当然用到servle,就要引入tomcat的servlet-api.jar包,在引入java通用包:rt.jar环境就配置好了
下面写入html(velocity默认的后缀名是vm,我习惯用html):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
</head>
<body>
#set( $this = "Velocity")
$this is so great!
<br>
#foreach( $name in $list )
$name 真的太奇妙啦!<br/>
#end
#set( $condition = true)
#if ($condition)
您选择的是1!
#else
您选择的是0!
#end
<br>
我的主页. <br>
</body>
</html>