关于JFinal 中Freemarker 使用Import 标签疑问

郭恩洲_OSC博客 发布于 2014/08/28 18:10
阅读 1K+
收藏 0

@jfinal

   我现在有个项目页面以前用到freemarker 然后我移植到Jfinl框架中,Freemarker中解析有Import标签页面出错。这应该非Jfinal问题,我怀疑Jfinal引入Freemarker时应该需要设置参数,貌似JFinal都是默认配置的. 还有一种可能是路径问题  绝对路径,相对路径都试过不起作用.

麻烦看下错误是什么问题导致

The failing instruction:
==> #import "/WEB-INF/layout/test2.ftl" a...  [in template "WEB-INF/view/center/test.ftl" at line 1, column 1]
	at com.jfinal.render.FreeMarkerRender.render(FreeMarkerRender.java:131)
	at com.jfinal.core.ActionHandler.handle(ActionHandler.java:92)
	at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:72)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:453)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:560)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1072)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:382)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1006)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
	at org.eclipse.jetty.server.Server.handle(Server.java:365)
	at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485)
	at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:926)
	at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:988)
	at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:635)
	at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
	at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628)
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
	at java.lang.Thread.run(Thread.java:722)
Caused by: freemarker.core._MiscTemplateException: Error reading imported template WEB-INF/layout/test2.ftl



页面写法:

<#import "/WEB-INF/layout/layout_center.ftl" as layout>
<#escape x as x?html>
<@layout.page title="" csses=["jquery/smoothness/jquery-ui-1.8.23.custom.css",
			                      "jquery/plugin/bootstrap-datetimepicker/css/datetimepicker.css"] 
               scripts=["js/center/center.js",
               'jquery/plugin/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js',
               'jquery/plugin/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js'] >



加载中
1
郭恩洲_OSC博客
郭恩洲_OSC博客

<#import "layout/test2.ftl" as layout>

test.ftl

<#import "/WEB-INF/view/layout/test2.ftl" as layout>
<@layout.page title="XXXX">
	test.ftl 的内容!
</@layout.page>



test2.ftl
<#macro page title>
    ${title?html}
    这是test2内容 欢迎你:<#nested>
</#macro>




0
吾同树
吾同树
引入路径改成<#import "layout_center.ftl" as layout>,试试?
郭恩洲_OSC博客
郭恩洲_OSC博客
谢谢 仔细检查下路径可以了 我太粗心了 还是Freemarker路径问题,和jfinal没有关系
0
JFinal
JFinal
通常我都用的 include,具体是理由忘记了,jfinal demo 中有include 的例子
返回顶部
顶部