日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Sitemesh 3 的使用及配置

發布時間:2023/12/19 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Sitemesh 3 的使用及配置 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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/luotaoyeah/p/3776879.html

總結

以上是生活随笔為你收集整理的Sitemesh 3 的使用及配置的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。