數據加載中……
          sitemesh 簡單入門
          2008年4月16日  edited by dingdangxiaoma
          引用
          sitemesh應用Decorator模式,用filter截取request和response,把頁面組件head,content,banner結合為一個完整的視圖。
          sitemesh 是OpenSymphony 組織下的子項目。
          準備:從官方下載 sitemesh包拷貝到你項目下的lib下。
          web.xml 添加以下內容。
              <filter>
                  
          <filter-name>sitemesh</filter-name>
                  
          <filter-class>
                      com.opensymphony.module.sitemesh.filter.PageFilter  //這是個過濾器。
                  
          </filter-class>
              
          </filter>

              
          <filter-mapping>
                  
          <filter-name>sitemesh</filter-name>
                  
          <url-pattern>/*</url-pattern>
              </filter-mapping>
          WEB-INF 下建立decorators.xml
          <?xml version="1.0" encoding="UTF-8"?>
          <decorators defaultdir="/decorators">
              
          <decorator name="main" page="main.jsp">      <!--裝飾頁面-->
                  
          <pattern>*</pattern>       <!-- 裝飾映射-->
              
          </decorator>
          </decorators>
          在webroot 下新建:decorators/main.jsp
          <%@ page contentType="text/html; charset=GBK"%>
          <%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator"
              prefix
          ="decorator"%>
          <html>
              
          <head>
                  
          <title>
          <decorator:title default="decorators" />
                  
          </title>
                  
          <decorator:head />
              
          </head>
              
          <body>
                  sitemesh的例子
                  
          <hr>
                  
          <decorator:body />
                  
          <hr>
                  DingDangXiaoMa@
          163.com 
              
          </body>
          </html>
          建立 index.jsp
          <%@ page contentType="text/html; charset=GBK"%>
          <html>
               
          <head>
                 
          <title>343</title>
               
          </head>
               
          <body>
                 
          <p>本頁只有一句,就是本句.</p>
               
          </body>
          </html>
          當通過訪問服務器時:http://localhost/sitemesh/index.jsp時。
          會看到:
          sitemesh的例子
          本頁只有一句,就是本句.
          DingDangXiaoMa@
          163.com
          這就輸出結果了。訪問的結果自動裝載上了main.jsp樣式。這就是添加了sitemesh 過濾的結果。
          這就是一個簡單的例子,只是說明了整個問題的應用,而沒有涉及到各個細節問題。
          當然,sitemesh 還有很多內容。支持的視圖不公包含了.jsp還有velocity freemarker等。
          參考資料:
          http://www.java3z.com/cwbwebhome/article/article2/2962.html?id=1668
          http://www.cjsdn.net/post/view?bid=29&id=178862

          posted on 2008-04-16 11:13 叮當小馬 閱讀(285) 評論(0)  編輯  收藏 所屬分類: OpenSymphony


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 德保县| 沙湾县| 临泽县| 柳河县| 印江| 合水县| 资源县| 乌鲁木齐县| 阿勒泰市| 通州区| 汤阴县| 自治县| 门源| 漠河县| 凤城市| 大安市| 濉溪县| 诏安县| 祥云县| 玛纳斯县| 肇州县| 家居| 刚察县| 邵阳市| 乌兰察布市| 嘉义县| 金堂县| 宁化县| 阿荣旗| 马关县| 大石桥市| 威远县| 襄垣县| 方城县| 岚皋县| 苗栗市| 晋中市| 凉城县| 巩义市| 江口县| 江门市|