velocity错误:ReferenceException

04-06-20 zxczf
public class Test {
	public static void main(String[] args) throws Exception {
		Zxczf zxczf = new Zxczf();
		zxczf.setAge("18");
		VelocityContext ctx = new VelocityContext();
		ctx.put("zxczf", zxczf);

		Velocity.init();
		FileWriter fw = new FileWriter("result.txt");
		Template template = Velocity.getTemplate("test.vm","gb2312");
		template.merge(ctx,fw);
		fw.close();
	}
}
class Zxczf {
	private String age;

	public void setAge(String age) {
		this.age = age;
	}
	public String getAge() {
		return age;
	}
	public String toString() {
		return getAge();
	}
}
<p>

test.vm

$zxczf.Age()
<p>

出现以下错误:

Sun Jun 20 20:19:50 CST 2004   [warn] org.apache.velocity.runtime.exception.ReferenceException: reference : template = test.vm [line 3,column 1] : $zxczf.Age() is not a valid reference.

怎么这么简单的例子都出错?想不通~~~

猜你喜欢