velocity錯誤:ReferenceException

zxczf發表於2004-06-20
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 class="indent">

test.vm

$zxczf.Age()
<p class="indent">

出現以下錯誤:

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.

怎麼這麼簡單的例子都出錯?想不通~~~

相關文章