我无法从 FTL 文件中的值堆栈中检索值。这是代码。
动作类拥有一个名为“名称”的属性
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 类获取到 FTL 的方法。提前致谢。