頁面修飾架構SiteMesh的簡單使用

來源:互聯網
上載者:User

SiteMesh 簡介;

SiteMesh 是一個網頁布局和修飾的架構,利用它可以將網頁的內容和頁面結構分離,以達到頁面結構共用的目的。

Sitemesh是由一個基於Web頁面配置、裝飾以及與現存Web應用整合的架構。它能協助我們在由大
量頁面構成的項目中建立一致的頁面配置和外觀,如一致的導航條,一致的banner,一致的著作權,等等。
它不僅僅能處理動態內容,如jsp,php,asp等產生的內容,它也能處理靜態內容,如htm的內容,
使得它的內容也符合你的頁面結構的要求。甚至於它能將HTML檔案象include那樣將該檔案作為一個面板
的形式嵌入到別的檔案中去。所有的這些,都是GOF的Decorator模式的最生動的實現。儘管它是由java語言來實現的,但它能與其他Web應用很好地整合。





sitemesh架構工作原理

結構圖:


流程圖:

開發步驟:

1.加入jar包

sitemesh-2.4.1.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. 在WEB-INF目錄下加入decorators.xml檔案

並進行配置;

<?xml version="1.0" encoding="ISO-8859-1"?><decorators defaultdir="/decorators">        <decorator name="main" page="main.jsp">        <pattern>/1.jsp</pattern>        <pattern>/2.jsp</pattern>        <pattern>/index.jsp</pattern>    </decorator></decorators>  

4. 在WEBRoot目錄下建立 /decorators/main.jsp檔案

引入decorator標籤:
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>

使用標籤(頁頭頁尾為裝飾的部分):

 頁頭<br/>
  <decorator:body></decorator:body>   <br/>
 頁尾<br/>
 
5.訪問http://localhost:8080/webName/index.jsp即可看到效果

 頁頭<br/>
  111111111            ---->1.jsp中<body>標籤中的內容
 頁尾<br/>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.