0

我无法从 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 的方法。提前致谢。

4

1 回答 1

0

我有一种方法可以从最近执行的动作类中获取值。只需将最后一条语句更改如下

template.process(invocation.getAction(), out);

谢谢

于 2010-03-13T15:52:20.777 回答