Templates 无法从自定义结果类型的值堆栈中获取ftl中的值
我无法从FTL文件中的值堆栈中检索值。这是代码 Action类包含一个名为“name”的属性Templates 无法从自定义结果类型的值堆栈中获取ftl中的值,templates,freemarker,Templates,Freemarker,我无法从FTL文件中的值堆栈中检索值。这是代码 Action类包含一个名为“name”的属性 private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } public String execute(){ setName("From value stack .. "); return SUCC
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String execute(){
setName("From value stack .. ");
return SUCCESS;
}
FTL代码:
${name}
自定义结果类型doExecute方法
Configuration configuration = new Configuration();
String templatePath = "/ftl";
ServletContext context = ServletActionContext.getServletContext();
configuration.setServletContextForTemplateLoading(context, templatePath);
configuration.setObjectWrapper(new DefaultObjectWrapper());
Template template = configuration.getTemplate("sample.ftl");
OutputStreamWriter out = new OutputStreamWriter(System.out);
template.process(ActionContext.getContext().getValueStack(), out);
我正在传递包含最近执行的操作的值堆栈。但FTL抛出了一个例外
表达式名称在sample.ftl的第1行第3列中未定义
我尝试使用传递会话而不是值堆栈,我可以在FTL中获得值
请给我建议一种从Action类到value stack的FTL获取值的方法。
谢谢你的帮助。我找到了一种从最近执行的Action类中获取值的方法。只需将最后一条语句更改如下
template.process(invocation.getAction(), out);
谢谢