1
我正在學習Struts 2.在使用FreeMarker模板創建視圖時,出現錯誤。我使用的Eclipse IDE,並在Tomcat中運行的應用程序8.使用<@ s.generator和迭代器標籤時獲取「Freemarker模板錯誤」
的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>
)
這是我在stackoverflow上的第一篇文章。我想知道我什麼時候能解決這個問題。它很早就解決了。謝謝。我喜歡你也爲我提供了這個參考。 :) – hvsharma
@hvsharma歡迎來到SO。很棒的第一篇文章 –
FreeMarker有自己的迭代器指令('#list'及其朋友)......我不知道Struts的最佳實踐是什麼,但這對我來說看起來很奇怪。 – ddekany