Sitemesh3的使用及配置

1 . Sitemesh 3 簡介

Sitemesh 是一個網頁布局和修飾的框架,基于 Servlet 中的 Filter,類似于 ASP.NET 中的‘母版頁’技術。參考:百度百科,相關類似技術:Apache Tiles。

官網:http://wiki.sitemesh.org/wiki/display/sitemesh/Home?。

2 . Sitemesh 3 下載

最新版本:3.0.0-SNAPSHOT

① GitHub 地址:https://github.com/sitemesh/sitemesh3

② maven:

1 <dependency>
2   <groupId>org.sitemesh</groupId> 3 <artifactId>sitemesh</artifactId> 4 <version>3.0.0</version> 5 </dependency>

3 . 配置 Sitemesh 3 過濾器

在 web.xml 中添加 Sitemesh Filter:?

復制代碼
 1 <web-app>
 2 
 3  ...  4  5 <filter>  6 <filter-name>sitemesh</filter-name>  7 <filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class>  8 </filter>  9 <filter-mapping> 10 <filter-name>sitemesh</filter-name> 11 <url-pattern>/*</url-pattern> 12 </filter-mapping> 13 14 </web-app>
復制代碼

4 . 準備兩個頁面:demo.html 和 decorator.html

① demo.html - “被裝飾的頁面”,實際要呈現的內容頁。

復制代碼
1 <!DOCTYPE html>
2 <html> 3 <head> 4 <title>內容頁的標題</title> 5 </head> 6 <body> 7  內容頁的body部分 8 </body> 9 </html>
復制代碼

② decorator.html - “裝飾頁面”,所謂的“母版頁”。

復制代碼
 1 <!DOCTYPE html>
 2 <html>  3 <head>  4 <title>  5 <sitemesh:write property='title' /> - ltcms  6 </title>  7 <sitemesh:write property='head' />  8 </head>  9 <body> 10 <header>header</header> 11 <hr /> 12  demo.html的title將被填充到這兒: 13 <sitemesh:write property='title' /><br /> 14  demo.html的body將被填充到這兒: 15 <sitemesh:write property='body' /> 16 <hr /> 17 <footer>footer</footer> 18 </body> 19 </html>
復制代碼

5 . 添加 /WEB-INF/sitemesh3.xml

復制代碼
1 <?xml version="1.0" encoding="UTF-8"?>
2 <sitemesh> 3 <!-- 指明滿足“/*”的頁面,將被“/WEB-INF/views/decorators/decorator.html”所裝飾 --> 4 <mapping path="/*" decorator="/WEB-INF/views/decorators/decorator.html" /> 5 6 <!-- 指明滿足“/exclude.jsp*”的頁面,將被排除,不被裝飾 --> 7 <mapping path="/exclude.jsp*" exclue="true" /> 8 </sitemesh>
復制代碼

6 . 運行效果

訪問 demo.html 頁面,實際效果如下:

7 . sitemesh3.xml 配置詳解

復制代碼
 1 <sitemesh>
 2     <!--默認情況下,  3  sitemesh 只對 HTTP 響應頭中 Content-Type 為 text/html 的類型進行攔截和裝飾,  4  我們可以添加更多的 mime 類型-->  5 <mime-type>text/html</mime-type>  6 <mime-type>application/vnd.wap.xhtml+xml</mime-type>  7 <mime-type>application/xhtml+xml</mime-type>  8  ...  9 10 <!-- 默認裝飾器,當下面的路徑都不匹配時,啟用該裝飾器進行裝飾 --> 11 <mapping decorator="/default-decorator.html"/> 12 13 <!-- 對不同的路徑,啟用不同的裝飾器 --> 14 <mapping path="/admin/*" decorator="/another-decorator.html"/> 15 <mapping path="/*.special.jsp" decorator="/special-decorator.html"/> 16 17 <!-- 對同一路徑,啟用多個裝飾器 --> 18 <mapping> 19 <path>/articles/*</path> 20 <decorator>/decorators/article.html</decorator> 21 <decorator>/decorators/two-page-layout.html</decorator> 22 <decorator>/decorators/common.html</decorator> 23 </mapping> 24 25 <!-- 排除,不進行裝飾的路徑 --> 26 <mapping path="/javadoc/*" exclue="true"/> 27 <mapping path="/brochures/*" exclue="true"/> 28 29 <!-- 自定義 tag 規則 --> 30 <content-processor> 31 <tag-rule-bundle class="com.something.CssCompressingBundle" /> 32 <tag-rule-bundle class="com.something.LinkRewritingBundle"/> 33 </content-processor> 34  ... 35 36 </sitemesh>
復制代碼

8 . 自定義 tag 規則

Sitemesh 3 默認只提供了 body,title,head 等 tag 類型,我們可以通過實現?TagRuleBundle 擴展自定義的 tag 規則:

復制代碼
 1 public class MyTagRuleBundle implements TagRuleBundle {
 2  @Override  3 public void install(State defaultState, ContentProperty contentProperty,  4  SiteMeshContext siteMeshContext) {  5 defaultState.addRule("myHeader", new ExportTagToContentRule(contentProperty.getChild("myHeader"), false));  6  7  }  8  9  @Override 10 public void cleanUp(State defaultState, ContentProperty contentProperty, 11  SiteMeshContext siteMeshContext) { 12  } 13 }
復制代碼

最后在 sitemesh3.xml 中配置即可:

1 <content-processor>
2     <tag-rule-bundle class="com.lt.common.ext.sitemesh3.MyTagRuleBundle" /> 3 </content-processor>

轉載于:https://www.cnblogs.com/duyinqiang/p/5237549.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/396724.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/396724.shtml
英文地址,請注明出處:http://en.pswp.cn/news/396724.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

等保項目流程

等級保護&#xff1a;直屬管理公安局 產品必須通過公安局安全許可證分級保護&#xff1a;直屬管理保密局 產品必須通過保密局銷售許可證等級保護&#xff1a;一般分為5級&#xff0c;目前最高用到是等保4級總概&#xff1a;定級——前期調研——總…

鴻蒙系統r如何升級,高歌猛進,鴻蒙系統升級機型再次確認,花粉:終等到!...

雖然華為手機現在的壓力非常大&#xff0c;但是在前進的道路上&#xff0c;真的充滿了樂觀精神&#xff0c;而且現在也算是一路高歌猛進了&#xff0c;發展路線開始加快了許多&#xff0c;無論是新機還是系統&#xff0c;都有著非常多的新消息。因為華為手機的實力很強&#xf…

Oracle快速備份表數據

Oracle數據庫中備份表數據。 例子&#xff1a; 1 create table table_name_bak as select * from table_name 1 create table table_name_bak as select * from table_name 2 where table_name.date between TO_DATE(2018-09-25,yyyy-MM-dd) and TO_DATE(2018-09-26,yyyy-MM-d…

git pull

今天在服務器上git pull是出現以下錯誤&#xff1a; error: Your local changes to the following files would be overwritten by merge: application/config/config.php application/controllers/home.php Please, commit your changes or stash them before you can merge. …

jq控制div是否展示_jQuery控制多個DIV的顯示和隱藏

問題補充&#xff1a;這是我寫的JSfunction Previous(){for(var i1;i<3;i){if(document.getElementById("d"i).style.display"block"){document.getElementById("d"(i-1)).style.display"block";}document.getElementById("d&…

C# 線程間不能調用剪切板的問題

最近做一個項目&#xff0c;需要用到線程&#xff0c;而且要用到剪切板&#xff0c;創建了一個子線程之后發現在子線程中剪切板上獲取不到數據&#xff0c;當時特別納悶&#xff0c;上網查資料&#xff0c;最后終于搞定&#xff0c;現將解決方法歸納如下&#xff1a; 第一步&am…

android studio背景模糊_[Android翻譯]CameraX:過去、現在和未來的一瞥

CameraX是一個未捆綁的Android Jetpack庫&#xff0c;它可以幫助你在Android應用中輕松添加攝像頭功能。傳統上&#xff0c;由于Android設備種類繁多&#xff0c;編程模型復雜&#xff0c;在Android上構建具有相機功能的應用程序非常困難。現在成千上萬的開發者都在使用CameraX…

html頁面根據分辨率縮放,html2Canvas根據不同分辨率,生成pdf內容自適應

根據屏幕大小不同&#xff0c;頁面內容自適應并一頁展示&#xff0c;應該如何實現// 導出頁面為PDF格式import html2Canvas from html2canvasimport JsPDF from jspdfexport default{install (Vue, options) {Vue.prototype.getPdf function () {setTimeout(() > {var titl…

【agc002f】Leftmost Ball(動態規劃)

【agc002f】Leftmost Ball&#xff08;動態規劃&#xff09; 題面 atcoder洛谷 題解 我們從前往后依次把每個顏色按順序來放&#xff0c;那么如果當前放的是某種顏色的第一個球&#xff0c;那么放的就會變成\(0\)號顏色&#xff0c;所以無論何時&#xff0c;\(0\)號顏色的數量不…

VS2010中的快捷鍵

一. VS2010中的快捷鍵 1&#xff1a; Ctrl Enter &#xff08;在光標指定位置的上 K C &#xff08;注釋&#xff09; Ctrl E U &#xff08;取消注釋&#xff09;  <>  Ctrl K U &#xff08;取消注釋&#xff09; 5&#xff1a; Tab &#xff08;增加縮進&a…

export function函數傳參_04 js高階函數(惰性函數、柯里化函數、compose函數)和單例設計模式...

高階函數的定義在《javascript設計模式和開發實踐》中是這樣定義的。函數可以作為參數被傳遞&#xff1b;函數可以作為返回值輸出。結合這兩個特點&#xff0c;首先想到的肯定是回調函數&#xff0c;回調函數也是高階函數的一種&#xff0c;除了回調函數&#xff0c;還有很多的…

Javascript構造函數的繼承

僅供學習參考&#xff0c;原文鏈接&#xff1a;http://www.ruanyifeng.com/blog/2010/05/object-oriented_javascript_inheritance.html 今天要介紹的是&#xff0c;對象之間的"繼承"的五種方法。 比如&#xff0c;現在有一個"動物"對象的構造函數。 funct…

python輸入字符串str_python字符串(str)

#value "raitOrEi"#v value.capitalize()#首字母大寫#print(v)#v1 v.casefold()#全部變小寫&#xff0c;不只是英文的&#xff0c;其他語言特殊的大小寫也變換#print(v1)#v2 v.lower()#只是英文變小寫#print(v2)#設置寬度&#xff0c;并將內容居中#20 代指總長度…

html5 audio api 錄音,如何使用HTML5 Web Audio API錄制我的聲音

在webkit瀏覽器上,您可以將get user media api與webkitGetUserMedia一起使用 – 如html5rocks所示.如果你想用你的聲音來創建javascript事件(例如控制屏幕上的對象)你必須分析傳入的聲音(例如事件1的高頻率 – 事件2的低頻率,語音分析要復雜得多,見下文)另外,還有chrome的’x-w…

修改密碼

在updateservlet.java中寫了方法&#xff0c;修改用戶密碼&#xff0c;代碼不成功求大神指教&#xff0c;代碼如下&#xff1a; updateadminpw.jsp <% page contentType"text/html;charsetgb2312" pageEncoding"gb2312" %><% taglib uri"ht…

MlLib--邏輯回歸筆記

批量梯度下降的邏輯回歸可以參考這篇文章&#xff1a;http://blog.csdn.net/pakko/article/details/37878837 看了一些Scala語法后&#xff0c;打算看看MlLib的機器學習算法的并行化&#xff0c;那就是邏輯回歸&#xff0c;找到package org.apache.spark.mllib.classification下…

mysql相關命令操作

2019獨角獸企業重金招聘Python工程師標準>>> 遠程連接容器中的mysql&#xff1a;mysql -h 192.168.5.116 -P 3306 -u root -p123456 啟動mysql容器&#xff1a; $ sudo docker pull mysql:5.6.35 $ sudo docker run --name mysql -p 12345:3306 -e MYSQL_ROOT_PASSW…

html實體注冊商標,html 注冊商標,html 注冊商標代碼

html中注冊的頁面用什么標簽寫好對于html中的注冊頁面&#xff0c;策朋專業辦理商標注冊、專利申請、版權登記保護&#xff0c;需要一個表格。使用標簽&#xff0c;輸入和按鈕標簽來組合成就。使用html作為注冊頁面。實際上&#xff0c;只要您能達到期望的效果&#xff0c;它的…

java已知一個二叉樹_#二叉樹復習#

#二叉樹復習#目錄滿二叉樹完全二叉樹平衡二叉樹二叉樹的主要性質--二叉樹的度--二叉樹的深度計算二叉樹的遍歷其他符號變量結點總數深度度為0的結點數/葉子結點數度為1的結點數度為2的結點數什么是滿二叉樹&#xff1f;二叉樹每層的結點數為。滿二叉樹總結點數&#xff1a;。圖…

hashtable - hashmap

http://www.importnew.com/24822.html轉載于:https://www.cnblogs.com/qinqiu/p/9711147.html