案例一

1.1、错误描述

 五月 28, 2014 9:56:48 下午 freemarker.log.JDK14LoggerFactory$JDK14Logger error
 严重: Template processing error: "Expression student.course is undefined on line 15, column 24 in course.ftl."

 Expression student.course is undefined on line 15, column 24 in course.ftl.
 The problematic instruction:
 ----------
 ==> ${student.course} [on line 15, column 22 in course.ftl]
 ----------

 Java backtrace for programmers:
 ----------
 freemarker.core.InvalidReferenceException: Expression student.course is undefined on line 15, column 24 in course.ftl.
     at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:125)
     at freemarker.core.Expression.getStringValue(Expression.java:118)
     at freemarker.core.Expression.getStringValue(Expression.java:93)
     at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
     at freemarker.core.Environment.visit(Environment.java:221)
     at freemarker.core.MixedContent.accept(MixedContent.java:92)
     at freemarker.core.Environment.visit(Environment.java:221)
     at freemarker.core.Environment.process(Environment.java:199)
     at freemarker.template.Template.process(Template.java:259)
     at com.you.freemarker.FreemarkerTemplate.printFtl(FreemarkerTemplate.java:77)
     at com.you.test.freemarker.FreemarkerTest.studentPrint(FreemarkerTest.java:141)
     at com.you.test.freemarker.FreemarkerTest.testCourse(FreemarkerTest.java:128)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
     at java.lang.reflect.Method.invoke(Unknown Source)
     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
     at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
     at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
     at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
     at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
     at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

 Expression student.course is undefined on line 15, column 24 in course.ftl.
 The problematic instruction:
 ----------
 ==> ${student.course} [on line 15, column 22 in course.ftl]
 ----------

 Java backtrace for programmers:
 ----------
 freemarker.core.InvalidReferenceException: Expression student.course is undefined on line 15, column 24 in course.ftl.
     at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:125)
     at freemarker.core.Expression.getStringValue(Expression.java:118)
     at freemarker.core.Expression.getStringValue(Expression.java:93)
     at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
     at freemarker.core.Environment.visit(Environment.java:221)
     at freemarker.core.MixedContent.accept(MixedContent.java:92)
     at freemarker.core.Environment.visit(Environment.java:221)
     at freemarker.core.Environment.process(Environment.java:199)
     at freemarker.template.Template.process(Template.java:259)
     at com.you.freemarker.FreemarkerTemplate.printFtl(FreemarkerTemplate.java:77)
     at com.you.test.freemarker.FreemarkerTest.studentPrint(FreemarkerTest.java:141)
     at com.you.test.freemarker.FreemarkerTest.testCourse(FreemarkerTest.java:128)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
     at java.lang.reflect.Method.invoke(Unknown Source)
     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
     at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
     at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
     at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
     at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
     at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
 <html>
   <head>
     <meta http-equiv="content-type" content="text/html; charset=UTF-8">
     <title>学生信息</title>

   </head>

   <body>
         姓名:张三丰
          性别:男
          年龄:16
          生日:1970-01-01
         地址:湖北省武汉市武昌洪山区
           QQ:78,451,214
                   课程:
 Expression student.course is undefined on line 15, column 24 in course.ftl.
 The problematic instruction:
 ----------
 ==> ${student.course} [on line 15, column 22 in course.ftl]
 ----------

 Java backtrace for programmers:
 ----------
 freemarker.core.InvalidReferenceException: Expression student.course is undefined on line 15, column 24 in course.ftl.
     at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:125)
     at freemarker.core.Expression.getStringValue(Expression.java:118)
     at freemarker.core.Expression.getStringValue(Expression.java:93)
     at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
     at freemarker.core.Environment.visit(Environment.java:221)
     at freemarker.core.MixedContent.accept(MixedContent.java:92)
     at freemarker.core.Environment.visit(Environment.java:221)
     at freemarker.core.Environment.process(Environment.java:199)
     at freemarker.template.Template.process(Template.java:259)
     at com.you.freemarker.FreemarkerTemplate.printFtl(FreemarkerTemplate.java:77)
     at com.you.test.freemarker.FreemarkerTest.studentPrint(FreemarkerTest.java:141)
     at com.you.test.freemarker.FreemarkerTest.testCourse(FreemarkerTest.java:128)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
     at java.lang.reflect.Method.invoke(Unknown Source)
     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
     at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
     at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
     at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
     at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
     at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

1.2、错误原因

Student类中的course属性没有赋值,而freemarker对为空的属性就会报错

  课程:${student.course}     

1.3、解决办法

在属性值后添加“!”

二,案例二

2.1,分析

上面的案例的前提条件是student不能为空,假如现在student为空了怎么办。

2.2,解决方案

freemarker.core.InvalidReferenceException: Expression ctt.contentType is undefined on line 46, column 91 in WEB-INF/ftl_lib/cms/style_content/style1-1_core.ftl. 
百度,google半天只说ftl文件中不能带人空值,但不知如何在ftl文件中判断为空,然后容掉这个错误。后来终于找到方法: 
[#if ctt.contentType??][${ctt.contentType.name} - ${ctt.ctgName}] [#else][${ctt.ctgName}][/#if] 
“??”判断是否为空。 
记下方便以后备用,同样希望给遇到同样问题的人带来帮助。

这种解决方案就是加一个if判断就好了。

三,案例三

1 <#list books as book>
2         <tr>
3         <td>书名:</td>
4         <td>${book}</td>
5         </tr>
6         </#list> 

报错

 1 freemarker.core.InvalidReferenceException: Expression books is undefined on line 9, column 24 in WEB-INF/ftl/showBook.ftl.
 2     at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:125)
 3     at freemarker.core.IteratorBlock.accept(IteratorBlock.java:100)
 4     at freemarker.core.Environment.visit(Environment.java:221)
 5     at freemarker.core.MixedContent.accept(MixedContent.java:92)
 6     at freemarker.core.Environment.visit(Environment.java:221)
 7     at freemarker.core.Environment.process(Environment.java:199)
 8     at freemarker.template.Template.process(Template.java:259)
 9     at org.apache.struts2.views.freemarker.FreemarkerResult.doExecute(FreemarkerResult.java:201)
10     at org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)
11     at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:374)
12     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:278)
13     at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
14     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
15     at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
16     at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
17     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
18     at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
19     at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
20     at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
21     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
22     at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
23     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
24     at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)
25     at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
26     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
27     at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)
28     at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
29     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
30     at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)
31     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
32     at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
33     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
34     at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90)
35     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
36     at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
37     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
38     at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
39     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
40     at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
41     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
42     at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
43     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
44     at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
45     at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
46     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
47     at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
48     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
49     at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
50     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
51     at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:192)
52     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
53     at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
54     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
55     at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
56     at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:511)
57     at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
58     at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
59     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
60     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
61     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
62     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
63     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
64     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
65     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
66     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
67     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
68     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
69     at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
70     at java.lang.Thread.run(Thread.java:619)
71 2012-11-26 14:11:33 org.apache.catalina.core.StandardWrapperValve invoke 

解决办法是:因为ftl是不能传入空值的。如果有空值 就会报这个的错误 :

只要做一下判断就行了

<#if books ??>

</#if>

代码 如下:

1 <#if books ??>
2         <#list books as book>
3         <tr>
4         <td>书名:</td>
5         <td>${book}</td>
6         </tr>
7         </#list>
8         </#if> 

四,案例四

4,1、错误描述

 六月 04, 2014 11:04:03 下午 freemarker.log.JDK14LoggerFactory$JDK14Logger error
 严重: Template processing error: "Expression maps.key is undefined on line 15, column 25 in map.ftl."

 Expression maps.key is undefined on line 15, column 25 in map.ftl.
 The problematic instruction:
 ----------
 ==> ${maps.key} [on line 15, column 23 in map.ftl]
 ----------

 Java backtrace for programmers:
 ----------
 freemarker.core.InvalidReferenceException: Expression maps.key is undefined on line 15, column 25 in map.ftl.
     at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:125)
     at freemarker.core.Expression.getStringValue(Expression.java:118)
     at freemarker.core.Expression.getStringValue(Expression.java:93)
     at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
     at freemarker.core.Environment.visit(Environment.java:221)
     at freemarker.core.MixedContent.accept(MixedContent.java:92)
     at freemarker.core.Environment.visit(Environment.java:221)
     at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:167)
     at freemarker.core.Environment.visit(Environment.java:428)
     at freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)
     at freemarker.core.Environment.visit(Environment.java:221)
     at freemarker.core.MixedContent.accept(MixedContent.java:92)
     at freemarker.core.Environment.visit(Environment.java:221)
     at freemarker.core.Environment.process(Environment.java:199)
     at freemarker.template.Template.process(Template.java:259)
     at com.you.freemarker.FreemarkerTemplate.printFtl(FreemarkerTemplate.java:77)
     at com.you.test.freemarker.FreemarkerTest.studentPrint(FreemarkerTest.java:210)
     at com.you.test.freemarker.FreemarkerTest.testMap(FreemarkerTest.java:197)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
     at java.lang.reflect.Method.invoke(Unknown Source)
     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
     at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
     at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
     at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
     at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
     at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

 Expression maps.key is undefined on line 15, column 25 in map.ftl.
 The problematic instruction:
 ----------
 ==> ${maps.key} [on line 15, column 23 in map.ftl]
 ----------

 Java backtrace for programmers:
 ----------
 freemarker.core.InvalidReferenceException: Expression maps.key is undefined on line 15, column 25 in map.ftl.
     at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:125)
     at freemarker.core.Expression.getStringValue(Expression.java:118)
     at freemarker.core.Expression.getStringValue(Expression.java:93)
     at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
     at freemarker.core.Environment.visit(Environment.java:221)
     at freemarker.core.MixedContent.accept(MixedContent.java:92)
     at freemarker.core.Environment.visit(Environment.java:221)
     at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:167)
     at freemarker.core.Environment.visit(Environment.java:428)
     at freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)
     at freemarker.core.Environment.visit(Environment.java:221)
     at freemarker.core.MixedContent.accept(MixedContent.java:92)
     at freemarker.core.Environment.visit(Environment.java:221)
     at freemarker.core.Environment.process(Environment.java:199)
     at freemarker.template.Template.process(Template.java:259)
     at com.you.freemarker.FreemarkerTemplate.printFtl(FreemarkerTemplate.java:77)
     at com.you.test.freemarker.FreemarkerTest.studentPrint(FreemarkerTest.java:210)
     at com.you.test.freemarker.FreemarkerTest.testMap(FreemarkerTest.java:197)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
     at java.lang.reflect.Method.invoke(Unknown Source)
     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
     at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
     at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
     at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
     at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
     at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
 <html>
   <head>
     <meta http-equiv="content-type" content="text/html; charset=UTF-8">
     <title>freemarker处理哈希表的内建函数</title>

   </head>

   <body>
           张三强

         1----
 Expression maps.key is undefined on line 15, column 25 in map.ftl.
 The problematic instruction:
 ----------
 ==> ${maps.key} [on line 15, column 23 in map.ftl]
 ----------

 Java backtrace for programmers:
 ----------
 freemarker.core.InvalidReferenceException: Expression maps.key is undefined on line 15, column 25 in map.ftl.
     at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:125)
     at freemarker.core.Expression.getStringValue(Expression.java:118)
     at freemarker.core.Expression.getStringValue(Expression.java:93)
     at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
     at freemarker.core.Environment.visit(Environment.java:221)
     at freemarker.core.MixedContent.accept(MixedContent.java:92)
     at freemarker.core.Environment.visit(Environment.java:221)
     at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:167)
     at freemarker.core.Environment.visit(Environment.java:428)
     at freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)
     at freemarker.core.Environment.visit(Environment.java:221)
     at freemarker.core.MixedContent.accept(MixedContent.java:92)
     at freemarker.core.Environment.visit(Environment.java:221)
     at freemarker.core.Environment.process(Environment.java:199)
     at freemarker.template.Template.process(Template.java:259)
     at com.you.freemarker.FreemarkerTemplate.printFtl(FreemarkerTemplate.java:77)
     at com.you.test.freemarker.FreemarkerTest.studentPrint(FreemarkerTest.java:210)
     at com.you.test.freemarker.FreemarkerTest.testMap(FreemarkerTest.java:197)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
     at java.lang.reflect.Method.invoke(Unknown Source)
     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
     at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
     at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
     at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
     at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
     at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

4.2、错误原因

 <#assign maps={"1":"张三丰","2":"李思思","3":"张三强","4":"王五"}>
      ${maps["3"]}

      <#assign keys=maps?keys>
      <#list keys as key>
         ${key}----${maps.key}
      </#list>

其中,${maps.key}未定义,获取hashmap中的描述不能这样取值

4.3、解决办法

 <#--freemarker HashMap取值-->
      <#assign maps={"1":"张三丰","2":"李思思","3":"张三强","4":"王五"}>
      ${maps["3"]}

      <#assign keys=maps?keys>
      <#list keys as key>
         ${key}----${maps[key]}
      </#list>

正确取值:${key}----${maps[key]}

maps.key改成
maps[key]

运行结果:

 <html>
   <head>
     <meta http-equiv="content-type" content="text/html; charset=UTF-8">
     <title>freemarker处理哈希表的内建函数</title>

   </head>

   <body>
           张三强

         1----张三丰
         2----李思思
         3----张三强
         4----王五
   </body>
 </html>

异常-----freemarker.core.InvalidReferenceException问题解决的更多相关文章

  1. freemarker.core.InvalidReferenceException: Expression stackObject.value.get(propertyName).toString() is undefined

    很奇怪的报错, 在实体中添加 toString方法后, 想在前台列表中使用 <s:debug标签调试, 发现报错如下: freemarker.core.InvalidReferenceExcep ...

  2. freemarker.core.InvalidReferenceException

    1.错误描述 freemarker.core.InvalidReferenceException:on line 68,column 18 in ftl/inc/incPro.ftl p.mainSe ...

  3. 解决 HTTP Status 500 - Unable to show problem report: freemarker.core.InvalidReferenceException:

    HTTP Status 500 - Unable to show problem report: freemarker.core.InvalidReferenceException: The foll ...

  4. 异常-----freemarker.core.ParseException: Encountered

    1.错误描述 freemarker.core.ParseException: Encountered " " at line 14, column 12 in myself.ftl ...

  5. 异常-----freemarker.core.ParseException: Unexpected end of file reached

    freemarker自定义标签 1.错误描述 freemarker.core.ParseException: Unexpected end of file reached. at freemarker ...

  6. 异常-----freemarker.core.ParseException: Encountered "string"

    1.错误描述 freemarker.core.ParseException: Encountered "string" at line 21, column 21 in type. ...

  7. 异常-----freemarker.core.ParseException: Token manager error

    一,案例一 1.1.错误描述 freemarker.core.ParseException: Token manager error: freemarker.core.TokenMgrError: L ...

  8. 异常-----freemarker.core.NonStringException

    一,案例一 1.1.错误描述 <html> <head> <meta http-equiv="content-type" content=" ...

  9. freemarker.core.InvalidReferenceException: [... Exception message was already printed; see it above ...]

    FreeMarker template error:The following has evaluated to null or missing:==> product  [in templat ...

随机推荐

  1. BZOJ 2337: [HNOI2011]XOR和路径 [高斯消元 概率DP]

    2337: [HNOI2011]XOR和路径 题意:一个边权无向连通图,每次等概率走向相连的点,求1到n的边权期望异或和 这道题和之前做过的高斯消元解方程组DP的题目不一样的是要求期望异或和,期望之间 ...

  2. BZOJ 3698: XWW的难题 [有源汇上下界最大流]

    3698: XWW的难题 题意:(1)A[N][N]=0:(2)矩阵中每行的最后一个元素等于该行前N-1个数的和:(3)矩阵中每列的最后一个元素等于该列前N-1个数的和.给A中的数进行取整操作(可以是 ...

  3. 51Nod 欢乐手速场1 B 序列变换[容斥原理 莫比乌斯函数]

    序列变换 alpq654321 (命题人)   基准时间限制:1 秒 空间限制:131072 KB 分值: 40 lyk有两序列a和b. lyk想知道存在多少对x,y,满足以下两个条件. 1:gcd( ...

  4. 让SpringMVC Restful API优雅地支持多版本

    好久没有更新博客,难得有空,记录一下今天写的一个小工具,供有需要的朋友参考. 在移动APP开发中,多版本接口同时存在的情况经常发生,通常接口支持多版本,有以下两种方式: 1.通过不同路径区分不同版本 ...

  5. Windows 动态链接库编程

    Windows 动态链接库编程  1.介绍Windows操作系统是应用最关的操作系统,因此动态链接库也为程序员所熟悉,即使对于普通的使用者来说,很多时候也会碰到.dll结尾的文件,这就是动态链接库文件 ...

  6. python基础dict,集合,文件

    字典是一种key:value的数据类型dict1{ 'stud1':'孙礼昭', 'stud2':'slz', 'stud3':'sunlizhao',}dict是无序的,key是唯一的  天生去重增 ...

  7. bootloader总体操作设计

    bootloarder设计蓝图(不想做设计师的程序员不是好程序员):bootloarder的作用:将linux内核启动起来设计方法:模仿u-bootu-boot:支持多种嵌入式cpu的bootloar ...

  8. javascript 利用FileReader和滤镜上传图片预览

    FileReader 对象允许Web应用程序异步读取存储在用户计算机上的文件(或原始数据缓冲区)的内容,使用 File或 Blob对象指定要读取的文件或数据. 1.FileReader接口的方法 Fi ...

  9. Qt滑动条设计与实现

    没有找到Qt的滑动条控件,所以自己写了一个,能够实现亮度调节.音量调节等功能. 效果如下图: 主要设计思路: 有些调节功能如对比度是有负值的,所以需要能对滑动条的数值范围进行设置,不局限于0~100 ...

  10. [记]WIndow/Linux 获取本机(全部)IPv4、IPv6、MAC地址方法 (C/C++)

    Linux 获取本机IP.MAC地址用法大全 //#include <sys/types.h> #include <ifaddrs.h> #include <sys/io ...