velocity是什么

2,149 阅读1分钟

一种J2EE的前端模版技术。

JSP,Freemarker差不多,都是用来展示网页内容的。

JSP不同的是velocity只能显示Action中的数据,不能处理数据。不能写java代码,但是可以使用Velocity标记。

Velocity的页面(模版)可是是任何类型(text/html)的文件。

比如Action中有如下两个属性.

class XxxAction{

private String title;

private String name;

public String execute(){

​ this.name = "Tom";

​ this.title="HelloWord";

​ return "velocity";

}

//getter & setter 必须要提供getter

}

struts.xml

a.html

velocity会将标记部分替换掉。

a.html

​ ${title}

​ hello ${name}

最终将会返回页面如下:

​ HelloWord

​ hello Tom

注:这个例子需要在struts2下,并且加入velocity jar包。