您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關(guān)SiteMesh整合Freemarker和velocity的使用方法,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。
FreeMarker 整合Struts2示例 https://www.jb51.net/article/197698.htm
SiteMesh入門示例 https://www.jb51.net/article/197668.htm
那么如何將Freemarker與SiteMesh結(jié)合起來使用,這在官方示例中已經(jīng)有了相關(guān)例子。
查看官方示例中decorators.xml文件,里面有一段是關(guān)于Freemarker使用的
<decorator name="freemarker" page="freemarker.ftl"> <pattern>/freemarker.html</pattern> </decorator>
也就是說請求freemarker.html時會攔截并處理,并發(fā)freemarker.ftl作為默認頁面處理
看一下freemarker.ftl的內(nèi)容,因為在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的結(jié)合是一樣的,看看關(guān)于他的配置
<decorator name="velocity" page="velocity.vm"> <pattern>/velocity.html</pattern> </decorator>
看看velocity.vm頁面內(nèi)容
<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>
關(guān)于SiteMesh整合Freemarker和velocity的使用方法就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。