數據加載中……
          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


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


          網站導航:
           
          主站蜘蛛池模板: 巨鹿县| 开化县| 无棣县| 保德县| 类乌齐县| 许昌县| 墨竹工卡县| 鄄城县| 两当县| 景宁| 玉树县| 车致| 抚宁县| 元江| 白河县| 石阡县| 祁阳县| 东宁县| 鹿泉市| 马尔康县| 眉山市| 榆树市| 万山特区| 邹城市| 布尔津县| 当阳市| 皋兰县| 辽源市| 商水县| 和田市| 岱山县| 枣庄市| 乡城县| 桃园县| 涞源县| 怀远县| 兴山县| 长葛市| 黄冈市| 章丘市| 寻乌县|