温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

SiteMesh整合Freemarker和velocity的使用方法

发布时间:2020-10-27 18:56:36 来源:亿速云 阅读:143 作者:Leah 栏目:开发技术

这篇文章将为大家详细讲解有关SiteMesh整合Freemarker和velocity的使用方法,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

FreeMarker 整合Struts2示例 https://www.jb51.net/article/197698.htm

SiteMesh入门示例 https://www.jb51.net/article/197668.htm

那么如何将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="external nofollow" 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="external nofollow" 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> 

关于SiteMesh整合Freemarker和velocity的使用方法就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI