SiteMesh结合Freemarker或velocity使用

Freemarker 入门示例 http://cuisuqiang.iteye.com/blog/2031768
FreeMarker 整合Struts2示例 http://cuisuqiang.iteye.com/blog/2031860

SiteMesh入门示例 http://cuisuqiang.iteye.com/blog/2066166 

 

那么如何将Freemarker与SiteMesh结合起来使用,这在官方示例中已经有了相关例子。
查看官方示例中decorators.xml文件,里面有一段是关于Freemarker使用的

<decorator name="freemarker" page="freemarker.ftl">
	<pattern>/freemarker.html</pattern>
</decorator>

 

也就是说请求freemarker.html时会拦截并处理,并发freemarker.ftl作为默认页面处理
看一下freemarker.ftl的内容,因为在JSP中是使用标签来获取Head或者Body的,所以在这个页面主要是看看如何获取这些元素。

<html>
	<head>
		<title>Freemarker Decorator - ${title}</title>
		<link href="${base}/decorators/main.css" rel="stylesheet" type="text/css">
	    ${head}
	</head>
    <body>
      <div id="pageTitle">${title}</div>
      <hr/>
      ${body}
      <div id="footer">
          <b>Disclaimer:</b> This site is an example site to demonstrate SiteMesh. It serves no other purpose.
      </div>
	</body>
</html>

 

可以看到,直接通过$来获取几个元素,${title}、 ${head}、${base}、${title}、${body}
velocity的结合是一样的,看看关于他的配置

<decorator name="velocity" page="velocity.vm">
	<pattern>/velocity.html</pattern>
</decorator>

 

看看velocity.vm页面内容

<html>
	<head>
		<title>Velocity Decorator - $title</title>
		<link href="$base/decorators/main.css" rel="stylesheet" type="text/css">
	    $head
	</head>
    <body>
      <div id="pageTitle">$title</div>
      <hr/>
      $body
      <div id="footer">
          <b>Disclaimer:</b> This site is an example site to demonstrate SiteMesh. It serves no other purpose.
      </div>
	</body>
</html>

 

不多解释了。

 

请您到ITEYE网站看 java小强 原创,谢谢!
http://cuisuqiang.iteye.com/

自建博客地址:http://www.javacui.com/ ,内容与ITEYE同步!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值