Sitemesh Demo
生活随笔
收集整理的這篇文章主要介紹了
Sitemesh Demo
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
簡介
- sitemesh是一個網頁布局與裝飾體系,主要應用于創建具有大量一致性用戶界面、導航與布局框架的站點。
- sitemesh攔截一切經過web server的靜態或動態生成的HTML頁面請求,處理頁面內容,并將其與一個或多個裝飾頁面進行融合,生成最終頁面。
- sitemesh也可用于構建由多個部分小頁面與布局組成的大型頁面。
- 可應用于基于java的web應用,也可用于離線內容。
JavaWeb應用sitemesh
1. 導入sitemesh.jar(下載sitemesh.jar)
2. 在web.xml中配置SiteMesh過濾器
<filter><filter-name>sitemesh</filter-name><filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class> </filter> <filter-mapping><filter-name>sitemesh</filter-name><url-pattern>/*</url-pattern> </filter-mapping>3. 編寫裝飾頁面與基礎頁面
裝飾頁面:
<?xml version="1.0" encoding="UTF-8" ?> <%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><title><decorator:title /></title></head> <body><h1>Header</h1><p><b>Navigation</b></p> <hr /><decorator:body /><hr /><h1>Footer</h1> </body> </html>其中<decorator:title />與<decorator:body />表示嵌入業務頁面對應的內容(title與body)
業務頁面:
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><title>Menu</title> </head> <body><h1>Beverages</h1><p>Cappucino $3.25</p><p>Latte $3.35</p><p>Espresso $2.00</p><p>Mocha $3.50</p> </body> </html>4. 配置SiteMesh裝飾規則
在WEB-INF/下配置decorators.xml來聲明需要對哪些頁面使用哪些頁面進行裝飾,以及哪些頁面不需要進行裝飾。
<?xml version="1.0" encoding="UTF-8"?> <decorators defaultdir="/decorators"><excludes><pattern>/data/menu*</pattern></excludes><decorator name="basic-theme" page="basic-theme.jsp"><pattern>/data/*</pattern></decorator> </decorators>上述配置聲明:
- 裝飾頁面的默認路徑為defaultdir="/decorators"
- 排除掉/data/下所有文件名以menu打頭的文件,符合此規則的頁面不受sitemesh影響
- 裝飾頁面為<decorator name="basic-theme" page="basic-theme.jsp">
- 裝飾規則:對項目中所有/data/下的頁面使用basic-theme.jsp進行裝飾。
下載
總結
以上是生活随笔為你收集整理的Sitemesh Demo的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java动态json入库_从JSon F
- 下一篇: ocsng mysql connecti