hushangjie 2015-04-14
具体概念在百度中都能找到,不赘述。可以参见http://airport.iteye.com/blog/23634
简单点说,Velocity与JSP类似。就是一个模板技术,通过后台JAVA程序进行变量的计算和赋值,前端模板vm文件使用后台计算的变量排版表示。优点是

<action name="testLogin" class="gravehistory.test.struts.LoginAction"> <result name="fail">/test/login.jsp</result> <result name="input">/test/login.jsp</result> <result name="success" type="velocity">/test/test-success.vm</result> </action>test-success.vm
<html>
<head>
<title>Hello</title>
</head>
<body>
Hello, $userName
</body>以上userName在LoginAction做为属性被定义<pre name="code" class="java">public class LoginAction extends ActionSupport {
private String userName;
private String passWord;
public void validate() {
//省略
}
public String execute() {
//useraname的赋值等
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassWord() {
return passWord;
}
public void setPassWord(String passWord) {
this.passWord = passWord;
}
}

#macro(test $msg)
<h1>*****$!{msg}*****<h1>
#endvelocimacro.library = WEB-INF/vm/macro.vm
<html>
<head>
<title>Hello</title>
</head>
<body>
Hello, #test($userName)
</body>
</html>
