这是我的场景:
…
private Integer id;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
…
…
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
…
<servlet>
<servlet-name>JSPSupportServlet</servlet-name>
<servlet-class>org.apache.struts2.views.JspSupportServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
…
…
<@s.include value="/invitation/inviter"/><#-- there is no variable id in this action -->
…
<span>${id}<span>
…
Error on line 63, column 61 in WEB-INF/ftl/invitation/ test.ftl
Expecting a string, date or number here, Expression id!0 is instead a freemarker.ext.beans.ArrayModel
The problematic instruction:
----------
==> ${id} [on line 63, column 59 in WEB-INF/ftl/invitation/test.ftl]
in user-directive page [on line 1, column 1 in WEB-INF/ftl/invitation/ test.ftl]
----------
Java backtrace for programmers:
----------
freemarker.core.NonStringException: Error on line 63, column 61 in WEB-INF/ftl/invitation/ test.ftl
Expecting a string, date or number here, Expression id!0 is instead a freemarker.ext.beans.ArrayModel
at freemarker.core.Expression.getStringValue(Expression.java:126)
at freemarker.core.Expression.getStringValue(Expression.java:93)
at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
at freemarker.core.Environment.visit(Environment.java:210)
我的代码有问题吗?
答案 0 :(得分:0)
据我所知,你试图显示TestAction对象而不是ID。
尝试这样做:
${testAction.id}
或在您目前的情况下:
${id.id}
这相当于:
(new TestAction()).getId()
或
existingTestAction.getId()
Taka在这里看到这个答案:Getting template text from FreeMarker in Struts2 app
此链接:http://struts.apache.org/2.0.6/docs/using-freemarker-templates.html
由于您未发布整个操作类,因此很难说出您在Action中添加了哪些模型数据。