<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    DANCE WITH JAVA

    開發(fā)出高質(zhì)量的系統(tǒng)

    常用鏈接

    統(tǒng)計

    積分與排名

    好友之家

    最新評論

    優(yōu)雅的解決web布局的問題 -- sitemesh的使用

    webwork的開發(fā)團隊opensymphony提供了一種優(yōu)雅的解決頁面布局的方法sitemesh。
    sitemesh應(yīng)用Decorator模式,用filter截取request和response,把頁面組件head,content,banner
    結(jié)合為一個完整的視圖。通常我們都是用include標簽在每個jsp頁面中來不斷的包含各種header,
    stylesheet, scripts and footer,現(xiàn)在,在sitemesh的幫助下,我們可以開心的刪掉他們了

    下邊是創(chuàng)建一個簡單實例的步驟:
    1,新建一個標準的web工程叫sitemesh
    在WebRoot下新建一個index.jsp,內(nèi)容如下

    1 <% @ page contentType = " text/html; charset=utf-8 " %>
    2 this  is index.jsp.
    3 it ' s a simple page 

    接著在webRoot下新建幾個目錄
    style2
    login
    shared
    在login下建立目錄style3
    然後把index.jsp分別復制到style2,login/style3,shared下
    現(xiàn)在訪問下邊的鏈接:
    http://localhost:8080/sitemesh/index.jsp
    http://localhost:8080/sitemesh/style2/index.jsp
    http://localhost:8080/sitemesh/login/style3/index.jsp
    http://localhost:8080/sitemesh/shared/index.jsp
    得到的結(jié)果是一樣的,那我們?nèi)绾巫屵@四個相同的index.jsp有不同的樣式呢。除了每個里邊加入include
    還有個解決辦法,就是sitemesh
    2,在opensymphony.sourceforge.net下載sitemesh.jar ,sitemesh-decorator.tld,sitemesh-page.tld
    三個文件。
    復制sitemesh.jar到WEB-INF/lib下,
    復制sitemesh-decorator.tld,sitemesh-page.tld到WEB-INF下
    把下邊這部分加入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>

    <taglib>
      <taglib-uri>sitemesh-decorator</taglib-uri>
      <taglib-location>/WEB-INF/sitemesh-decorator.tld</taglib-location>
    </taglib>

    <taglib>
      <taglib-uri>sitemesh-page</taglib-uri>
      <taglib-location>/WEB-INF/sitemesh-page.tld</taglib-location>
    </taglib>
    --------------------------------------------------------------------------------
    在WEB-INF下建立一個decorators.xml,內(nèi)容如下
    excludes代表不使用的部分
    其它三個是匹配url,使用style
    --------------------------------------------------------------------------
    <decorators defaultdir="/decorators">
        <excludes>
            <pattern>/shared/*</pattern>   
        </excludes>
        <decorator name="style1" page="style1.jsp">
            <pattern>/*</pattern>
        </decorator>
        <decorator name="style2" page="style2.jsp">
            <pattern>/style2/*</pattern>
        </decorator>
       
        <decorator name="style3" page="style3.jsp">
            <pattern>/*/style3/*</pattern>
        </decorator>
    </decorators>
    --------------------------------------------------------------------------
    在WebRoot下新建一個目錄decorators
    然後在下邊建立三個jsp文件,內(nèi)容如下
    ------------------------------------------------------------------
    <%@ page contentType="text/html; charset=utf-8"%>
    <%@ taglib uri="sitemesh-decorator" prefix="decorator" %>
    <html>
      <head>
        <title><decorator:title default="裝飾器頁面..." /></title>
        <decorator:head />
      </head>
      <body>
        <p><font color="red">this is style2's header</font></p>
        <hr>
        <decorator:body />
        <hr>
        <p><font color="red">this is style1's footer</font></p>
      </body>
    </html>
    ------------------------------------------------------------------

    <%@ page contentType="text/html; charset=utf-8"%>
    <%@ taglib uri="sitemesh-decorator" prefix="decorator" %>

    <html>
      <head>
        <title><decorator:title default="裝飾器頁面..." /></title>
        <decorator:head />
      </head>
      <body>
        <p><font color="green">this is style2's header</font></p>
        <hr>
        <decorator:body />
        <hr>
        <p><font color="green">this is style2's footer</font></p>
      </body>
    </html>

    ------------------------------------------------------------------
    <%@ page contentType="text/html; charset=utf-8"%>
    <%@ taglib uri="sitemesh-decorator" prefix="decorator" %>

    <html>
      <head>
        <title><decorator:title default="裝飾器頁面..." /></title>
        <decorator:head />
      </head>
      <body>
        <p><font color="blue">this is style3's header</font></p>
        <hr>
        <decorator:body />
        <hr>
        <p><font color="blue">this is style3's footer</font></p>
      </body>
    </html>
    ------------------------------------------------------------------
    再次訪問
    http://localhost:8080/sitemesh/index.jsp
    http://localhost:8080/sitemesh/style2/index.jsp
    http://localhost:8080/sitemesh/login/style3/index.jsp
    http://localhost:8080/sitemesh/shared/index.jsp
    看到變化了吧。這只是個簡單的展示,仔細思考一下你的需求,你能作出更好的布局方式。
    sitemesh真不錯。重要是學習簡單20分種就搞定了

    posted on 2006-12-05 17:17 dreamstone 閱讀(4035) 評論(1)  編輯  收藏 所屬分類: web框架

    評論

    # re: 優(yōu)雅的解決web布局的問題 -- sitemesh的使用 2006-12-06 10:26 loocky

    sitemesh的編碼有些問題,我在移動的一個項目中用過,SITEmesh 主要用FILTER來DECORATE頁面,其實很不錯的,避免了FRAME,很不錯的  回復  更多評論   

    主站蜘蛛池模板: 国产精品免费大片| 亚洲AV永久无码精品| 日本h在线精品免费观看| 国产精品视频免费| 亚洲AⅤ无码一区二区三区在线| 亚洲乱码日产一区三区| 亚洲色欲色欱wwW在线| 亚洲欧洲免费视频| 国产成人综合久久精品免费 | 免费一级大黄特色大片| 日韩电影免费观看| 一二三四影视在线看片免费 | 免费精品国产自产拍在线观看 | 久久精品国产亚洲AV无码娇色| 国产在线观看麻豆91精品免费 | 亚洲黄色高清视频| a级在线观看免费| 久久久久久A亚洲欧洲AV冫| 亚洲欧洲日产国码久在线| 免费A级毛片无码无遮挡内射| 久久亚洲国产精品一区二区| 自拍偷自拍亚洲精品播放| 手机在线免费视频| 亚洲七久久之综合七久久| 亚洲色大成网站www永久| 国产亚洲精品成人AA片| 久久精品国产免费观看三人同眠| 亚洲日韩精品无码专区网址| 国产亚洲人成在线影院| 香蕉视频免费在线播放| 草久免费在线观看网站| 毛片a级毛片免费播放100| 成人一a毛片免费视频| 久久亚洲日韩精品一区二区三区| 美女黄频免费网站| 午夜亚洲国产成人不卡在线| 亚洲国产系列一区二区三区| 中文字幕免费视频一| 噜噜综合亚洲AV中文无码| 亚洲人成色7777在线观看| 久久久久久国产a免费观看黄色大片|