我正在学习Struts 2.在使用FreeMarker模板创建视图时,我收到一个错误。我正在使用Eclipse IDE并在Tomcat 8中运行该应用程序。
Freemarker代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>Sample...(FreeMarker)</h1><br><br>
<div>
<@s.generator separator="," val="%{'15,20,30,40,50'}">
Last entered protein Values -:<br>
<@s.iterator>
<@s.property /><br>
</@s.iterator>
</@s.generator>
</div>
</body>
</html>
Eclipse控制台跟踪日志:
> Jul 14, 2016 8:19:02 PM
> com.opensymphony.xwork2.util.logging.jdk.JdkLogger error SEVERE:
> Exception occurred during processing request: The following has
> evaluated to null or missing:
> ==> s.generator [in template "WEB-INF/content/enter-protein.ftl" at line 10, column 11]
>
> ---- Tip: It's the step after the last dot that caused this error, not those before it.
> ---- Tip: If the failing expression is known to be legally refer to something that's null or missing, either specify a default value like
> myOptionalVar!myDefault, or use <#if
> myOptionalVar??>when-present<#else>when-missing</#if>. (These only
> cover the last step of the expression; to cover the whole expression,
> use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
> ----
>
> ---- FTL stack trace ("~" means nesting-related):
> - Failed at: @s.generator separator="," val="%{'15... [in template "WEB-INF/content/enter-protein.ftl" at line 16, column 9]
> ---- FreeMarker template error: The following has evaluated to null or missing:
> ==> s.generator [in template "WEB-INF/content/enter-protein.ftl" at line 16, column 11]
>
> ---- Tip: It's the step after the last dot that caused this error, not those before it.
> ---- Tip: If the failing expression is known to be legally refer to something that's null or missing, either specify a default value like
> myOptionalVar!myDefault, or use <#if
> myOptionalVar??>when-present<#else>when-missing</#if>. (These only
> cover the last step of the expression; to cover the whole expression,
> use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
> ----
>
> ---- FTL stack trace ("~" means nesting-related):
> - Failed at: @s.generator separator="," val="%{'15... [in template "WEB-INF/content/enter-protein.ftl" at line 16, column 9]
> ----
>
> Java stack trace (for programmers):
> ---- freemarker.core.InvalidReferenceException: [... Exception message was already printed; see it above ...] at
> freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:116)
> at freemarker.core.UnifiedCall.accept(UnifiedCall.java:112) at
> freemarker.core.Environment.visit(Environment.java:312) at
> freemarker.core.MixedContent.accept(MixedContent.java:62) at
> freemarker.core.Environment.visit(Environment.java:312) at
> freemarker.core.Environment.process(Environment.java:290) at
> freemarker.template.Template.process(Template.java:312) at
> org.apache.struts2.views.freemarker.FreemarkerResult.doExecute(FreemarkerResult.java:223)
> at
> org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:191) at
.
.
.
.
........................ So on...........
奇怪的是,当我在JSP中尝试相同的操作时,它完美无瑕!
(在JSP中,我们使用<s:something>
而不是<@s.something>
)
答案 0 :(得分:0)
<s:generator>
标记很简单,不是可以在FreeMarker模板中使用的那种标记*。
好的部分是:实际上根本不需要它。您可以使用<s:iterator>
标记w / o <s:generator>
。
使用iterator标签的value
属性设置可迭代源和OGNL表达式{e1,e2,e3}
以创建列表。
<@s.iterator value="{15,20,30,40,50}">
<@s.property /><br>
</@s.iterator>
*想知道您可以在FreeMarker模板中使用哪些Struts2标签?看到
DefaultTagLibrary#getDirectiveClasses
方法。