Jfinal BBS freemaker出错

dreamx2015 发布于 2016/01/16 10:14
阅读 1K+
收藏 0

@朋也 你好,想跟你请教个问题:

The failing instruction (FTL stack trace):
----------
==> #if session.user?? && session.user.mi...  [in template "ftl/front/common/sidebar.html" in macro "sidebar" at line 57, column 5]
    @sidebar sidebar_user_info=sidebar_us...  [in template "ftl/front/common/_layout.html" in macro "html" at line 74, column 17]
    @html title="首页 - \${siteTitle!}" des...  [in template "ftl/front/index.html" at line 2, column 1]
----------


Java stack trace (for programmers):
----------
freemarker.core.InvalidReferenceException: [... Exception message was already printed; see it above ...]
at freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:98)
at freemarker.core.EvalUtil.coerceModelToString(EvalUtil.java:382)
at freemarker.core.Expression.evalAndCoerceToString(Expression.java:115)
at freemarker.core.MiscellaneousBuiltins$dateBI._eval(MiscellaneousBuiltins.java:83)
at freemarker.core.Expression.eval(Expression.java:111)
at freemarker.core.EvalUtil.compare(EvalUtil.java:147)
at freemarker.core.ComparisonExpression.evalToBoolean(ComparisonExpression.java:103)
at freemarker.core.AndExpression.evalToBoolean(AndExpression.java:68)
at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:84)
at freemarker.core.Environment.visitByHiddingParent(Environment.java:286)
at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:86)
at freemarker.core.Environment.visit(Environment.java:265)
at freemarker.core.MixedContent.accept(MixedContent.java:93)
at freemarker.core.Environment.visit(Environment.java:265)
at freemarker.core.Macro$Context.runMacro(Macro.java:209)
at freemarker.core.Environment.visit(Environment.java:694)
at freemarker.core.UnifiedCall.accept(UnifiedCall.java:116)
at freemarker.core.Environment.visit(Environment.java:265)
at freemarker.core.MixedContent.accept(MixedContent.java:93)
at freemarker.core.Environment.visit(Environment.java:265)
at freemarker.core.Macro$Context.runMacro(Macro.java:209)
at freemarker.core.Environment.visit(Environment.java:694)
at freemarker.core.UnifiedCall.accept(UnifiedCall.java:116)
at freemarker.core.Environment.visit(Environment.java:265)
at freemarker.core.MixedContent.accept(MixedContent.java:93)
at freemarker.core.Environment.visit(Environment.java:265)
at freemarker.core.Environment.process(Environment.java:243)
at freemarker.template.Template.process(Template.java:277)
at com.jfinal.render.FreeMarkerRender.render(FreeMarkerRender.java:128)
at com.jfinal.core.ActionHandler.handle(ActionHandler.java:93)
at cn.jfinalbbs.handler.HtmlHandler.handle(HtmlHandler.java:17)
at com.jfinal.plugin.druid.DruidStatViewHandler.handle(DruidStatViewHandler.java:75)
at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:72)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2517)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2506)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)


2016-01-16 11:10:29
[ERROR]-[Thread: http-apr-8080-exec-9]-[com.jfinal.core.ActionHandler.handle()]: /
com.jfinal.render.RenderException: freemarker.core.InvalidReferenceException: The following has evaluated to null or missing:
==> session.today  [in template "ftl/front/common/sidebar.html" at line 57, column 57]


Tip: If the failing expression is known to be legally null/missing, either specify a default value with 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 parenthessis: (myOptionVar.foo)!myDefault, (myOptionVar.foo)??


The failing instruction (print stack trace for 2 more):
==> #if session.user?? && session.user.mi...  [in template "ftl/front/common/sidebar.html" in macro "sidebar" at line 57, column 5]
at com.jfinal.render.FreeMarkerRender.render(FreeMarkerRender.java:130)
at com.jfinal.core.ActionHandler.handle(ActionHandler.java:93)
at cn.jfinalbbs.handler.HtmlHandler.handle(HtmlHandler.java:17)
at com.jfinal.plugin.druid.DruidStatViewHandler.handle(DruidStatViewHandler.java:75)
at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:72)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2517)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2506)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: freemarker.core.InvalidReferenceException: The following has evaluated to null or missing:
==> session.today  [in template "ftl/front/common/sidebar.html" at line 57, column 57]


Tip: If the failing expression is known to be legally null/missing, either specify a default value with 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 parenthessis: (myOptionVar.foo)!myDefault, (myOptionVar.foo)??


The failing instruction (print stack trace for 2 more):
==> #if session.user?? && session.user.mi...  [in template "ftl/front/common/sidebar.html" in macro "sidebar" at line 57, column 5]
at freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:98)
at freemarker.core.EvalUtil.coerceModelToString(EvalUtil.java:382)
at freemarker.core.Expression.evalAndCoerceToString(Expression.java:115)
at freemarker.core.MiscellaneousBuiltins$dateBI._eval(MiscellaneousBuiltins.java:83)
at freemarker.core.Expression.eval(Expression.java:111)
at freemarker.core.EvalUtil.compare(EvalUtil.java:147)
at freemarker.core.ComparisonExpression.evalToBoolean(ComparisonExpression.java:103)
at freemarker.core.AndExpression.evalToBoolean(AndExpression.java:68)
at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:84)
at freemarker.core.Environment.visitByHiddingParent(Environment.java:286)
at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:86)
at freemarker.core.Environment.visit(Environment.java:265)
at freemarker.core.MixedContent.accept(MixedContent.java:93)
at freemarker.core.Environment.visit(Environment.java:265)
at freemarker.core.Macro$Context.runMacro(Macro.java:209)
at freemarker.core.Environment.visit(Environment.java:694)
at freemarker.core.UnifiedCall.accept(UnifiedCall.java:116)
at freemarker.core.Environment.visit(Environment.java:265)
at freemarker.core.MixedContent.accept(MixedContent.java:93)
at freemarker.core.Environment.visit(Environment.java:265)
at freemarker.core.Macro$Context.runMacro(Macro.java:209)
at freemarker.core.Environment.visit(Environment.java:694)
at freemarker.core.UnifiedCall.accept(UnifiedCall.java:116)
at freemarker.core.Environment.visit(Environment.java:265)
at freemarker.core.MixedContent.accept(MixedContent.java:93)
at freemarker.core.Environment.visit(Environment.java:265)
at freemarker.core.Environment.process(Environment.java:243)
at freemarker.template.Template.process(Template.java:277)
at com.jfinal.render.FreeMarkerRender.render(FreeMarkerRender.java:128)
... 22 more


登陆的时候报了一个这样的错误

加载中
0
吃菜的鸟
吃菜的鸟

session.user?? && session.user.mi... 

数据模型里央没有session这个对象。

jfinal和spring mvc不同,jfinal只把request的属性存在了数据模型里面。没有把session的存进去。

(session.user)??如果你这样写就不会报错,但是只能解决错误,如果你不手动把session的属性存到数据模型里面,user是取不到的。解决方法很多种,看自己喜欢哪种。

0
朋也
朋也
你这是最新代码吗?更新一下最新的代码在看看
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部