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

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

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

    love fish大鵬一曰同風(fēng)起,扶搖直上九萬(wàn)里

    常用鏈接

    統(tǒng)計(jì)

    積分與排名

    friends

    link

    最新評(píng)論

    使用SiteMesh簡(jiǎn)化網(wǎng)頁(yè)布局(轉(zhuǎn))

    在公司項(xiàng)目使用了 Appfuse ,其帶有 SiteMesh 對(duì)于網(wǎng)頁(yè)布局簡(jiǎn)化讓我感覺(jué)很好用,本文旨在對(duì)對(duì) Sitemesh 的基本原理和在項(xiàng)目中使用 Sitemesh 的實(shí)現(xiàn)流程、使用技巧的介紹。

    1.?? 基本原理

    SiteMesh 是以 Servlet 2.3API 為基礎(chǔ)。它包含一個(gè)引擎,用來(lái)解析輸出的網(wǎng)頁(yè)或者網(wǎng)頁(yè)片段,決定是否需要應(yīng)用裝飾器以及合并合適的裝飾器。

    ?????? SiteMesh 與應(yīng)用內(nèi)容無(wú)關(guān),適用的內(nèi)容格式包括 Html JSP Servlet XSL ,甚至 CGI

    ?

    2.?? 實(shí)現(xiàn)流程

    1)? 當(dāng)為 Servlet 容器指定一個(gè) Http 請(qǐng)求時(shí), SiteMesh 截取請(qǐng)求,使用一個(gè) Servlet Filter ,然后捕捉 Html 結(jié)果。

    2)? 然后這個(gè) Html 被解析,并且任何相關(guān)的內(nèi)容都被提取到一個(gè) Page 對(duì)象中。

    3)? 詢問(wèn) DecoratorMapper 來(lái)確定那一個(gè)裝飾器需要被應(yīng)用。

    4)? Servlet 向包含裝飾器的 JSP 發(fā)送請(qǐng)求。

    5 )裝飾器生成帶有從 page 對(duì)象中獲得的內(nèi)容的 Html 布局。

    大致流程如下圖:

    ?


    ???????? Sitemesh
    這樣的好處是,所有具體業(yè)務(wù)頁(yè)面的開(kāi)發(fā)者無(wú)需考慮該頁(yè)面將處在最終輸出頁(yè)面的那個(gè)位置。無(wú)需 include 一大堆頁(yè)面,以后如果系統(tǒng)整體改版,那么只需要改寫(xiě)裝飾器頁(yè)面及重新配置裝飾規(guī)則即可完成,方便快捷,可維護(hù)性極好。

    ?

    3.?? 在項(xiàng)目中使用 Sitemesh

    1.???????? sitemesh_[version].jar 包加到 WEB-INF\lib

    2.???????? 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 > ?

    ?

    ?????? 表示對(duì)系統(tǒng)中所有 url 請(qǐng)求均使用 sitemesh Filter 進(jìn)行攔截。

    3.???????? WEB-INF 下配置 sitemesh.xml decorator.xml 配置文件。

    Sitemesh.xml

    ?

    < sitemesh > ?

    ????
    < property? name ="decorators-file" ?value ="/WEB-INF/decorators.xml" /> ?

    ????
    < excludes? file ="${decorators-file}" /> ?

    ????
    < page-parsers > ?

    ????????
    < parser? default ="true" ?class ="com.opensymphony.module.sitemesh.parser.HTMLPageParser" /> ?

    ????????
    < parser? content-type ="text/html" ?

    class
    ="com.opensymphony.module.sitemesh.parser.HTMLPageParser" /> ?

    ????????
    < parser? content-type ="text/html;charset=ISO-8859-1" ?

    class
    ="com.opensymphony.module.sitemesh.parser.HTMLPageParser" /> ?

    ????
    </ page-parsers > ?

    ????
    < decorator-mappers > ?

    ??????????????????
    <!-- ?for?print? --> ?

    ????????
    < mapper? class ="com.opensymphony.module.sitemesh.mapper.PrintableDecoratorMapper" > ?

    ????????????????????????????
    < param? name ="decorator" ?value ="printable" ? /> ?

    ????????????????????????????
    < param? name ="parameter.name" ?value ="printable" ? /> ?

    ????????????????????????????
    < param? name ="parameter.value" ?value ="true" ? /> ?

    ????????
    </ mapper > ?

    ????????
    < mapper? class ="com.opensymphony.module.sitemesh.mapper.ConfigDecoratorMapper" > ?

    ????????????
    < param? name ="config" ?value ="${decorators-file}" /> ?

    ????????
    </ mapper > ?

    ????
    </ decorator-mappers > ?

    </ sitemesh > ?

    ?

    ?

    Decorator.xml

    ?

    < decorators? defaultdir ="/decorators" > ?

    ????
    < excludes > ?

    ????????
    < pattern > /demos/* </ pattern > ?

    ????????
    < pattern > /resources/* </ pattern > ?

    ????????
    < pattern > /test* </ pattern > ?

    ????????
    < pattern > /FCKeditor/* </ pattern > ?

    ????
    </ excludes > ?

    ?????????
    <!-- ?decorator?for?print(has?parameter:?printable=true) --> ?

    ????
    < decorator? name ="printable" ?page ="decPrintable.jsp" /> ?

    ?????????
    < decorator? name ="login" ?page ="decLogin.jsp" > ?

    ???????????????????
    < pattern > *login* </ pattern > ?????????? <! —url?映射模式?-- > ?

    ?????????
    </ decorator > ?

    ????
    < decorator? name ="default" ?page ="decDefault.jsp" > ?

    ????????
    < pattern > /* </ pattern > ???????????????? <! —?缺省的裝飾器?-- > ?

    ????
    </ decorator > ?

    </ decorators > ?

    ?

    sitemesh.xml 中配置了兩個(gè) DecoratorMapper PrintableDecoratorMapper ConfigDecoratorMapper

    PrintableDecoratorMapper 是供打印專用,在 url 后加上 printable=true 即會(huì)使用 decorator.xml 中指定的 printable 裝飾器來(lái)對(duì)頁(yè)面進(jìn)行裝飾,一般來(lái)說(shuō)打印頁(yè)面是只需要打印本頁(yè)面的內(nèi)容,其余的如頭、腳、導(dǎo)航欄、左右菜單等是不需要打印的,通過(guò)裝飾器可以輕松實(shí)現(xiàn)打印頁(yè)面的過(guò)濾。

    4.???????? 創(chuàng)建一個(gè)裝飾器 JSP 頁(yè)面,我建議所有裝飾器頁(yè)面放到 decorators 目錄,并且以 dec[ 功能 ].jsp 作為命名方式,如 decPrintable.jsp decDefault.jsp

    下面是一個(gè)裝飾器的代碼:

    ?

    <! DOCTYPE?html?PUBLIC? " -//W3C//DTD?XHTML?1.0?Transitional//EN "
    ????
    " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
    ????????
    <%-- ?Include?common?set?of?tag?library?declarations? for ?each?layout? --%>
    <% @?include?file = " /common/taglibs.jsp " %>

    < html?xmlns = " http://www.w3.org/1999/xhtml " ?xml:lang = " en " >
    ????
    < head >
    ???????? < decorator:head />
    ????
    </ head >
    < body
    < decorator:getProperty?property = " body.id " ?writeEntireProperty = " true " />
    < decorator:getProperty?property = " body.onload " ?writeEntireProperty = " true " />
    < decorator:getProperty?property = " body.onunload " ?writeEntireProperty = " true " />
    > ??????
    ????????
    <% @?include?file = " /common/header.jsp " %>
    ?????????? ? < h1 >< decorator:getProperty?property = " page.heading " /></ h1 > ?
    ????????????
    <% @?include?file = " /common/messages.jsp " ? %>
    ????????????
    < decorator:body />
    ???????? < jsp:include?page = " /common/footer.jsp " />
    </ body >
    </ html >

    ?

    注意其 <decorator:…> 標(biāo)簽,這些標(biāo)簽將被裝飾的 page 頁(yè)面的相應(yīng)內(nèi)容作為屬性傳入。 Page 頁(yè)面的相關(guān)內(nèi)容將放在 decorator 標(biāo)簽所指定的位置。

    Title :標(biāo)題

    Head :頭部,一般是公共的 js css meta

    Body :被裝飾的 page 的主體內(nèi)容。

    5 Sitemesh 通過(guò)在 sitemesh.xml 中配置 DecoratorMapper 配置映射器,通過(guò)在 decorator.xml 中配置裝飾器文件及其匹配方式。當(dāng)有頁(yè)面需要輸出到客戶端時(shí),將根據(jù)這些配置選擇相應(yīng)的裝飾器來(lái)進(jìn)行裝飾,將裝飾結(jié)果返回給客戶界面。

    ?

    4.?? 參考資料

    關(guān)于 Sitemesh api 及詳細(xì)使用說(shuō)明可以參看其官方網(wǎng)站

    http://www.opensymphony.com/sitemesh

    posted on 2007-03-22 11:14 liaojiyong 閱讀(502) 評(píng)論(0)  編輯  收藏 所屬分類: Other

    主站蜘蛛池模板: 在线观看亚洲天天一三视| 国产精品自在自线免费观看| 中文字幕精品亚洲无线码一区| 色偷偷尼玛图亚洲综合| 午夜高清免费在线观看| 亚洲乱色熟女一区二区三区蜜臀| 国内自产拍自a免费毛片| 亚洲成aⅴ人片久青草影院按摩| 日韩激情无码免费毛片| 国产亚洲漂亮白嫩美女在线 | 免费无码成人AV在线播放不卡| 亚洲成av人片天堂网| 91福利视频免费观看| 亚洲国产日韩精品| 国产又长又粗又爽免费视频| 一级毛片完整版免费播放一区| 久久亚洲色一区二区三区| a级特黄毛片免费观看| 亚洲成aⅴ人片在线观| 日本最新免费不卡二区在线| 一区二区视频在线免费观看| 亚洲AV无码专区国产乱码电影 | 中文字幕免费在线看线人 | 91视频国产免费| 国产亚洲福利精品一区二区| 黑人精品videos亚洲人| 免费专区丝袜脚调教视频| 亚洲AV无码XXX麻豆艾秋| 亚洲人成网7777777国产 | 免费一级一片一毛片| 大地资源网高清在线观看免费| 亚洲欧洲日本天天堂在线观看| 日本一区免费电影| 日本卡1卡2卡三卡免费| 亚洲人成电影网站色www| 国产亚洲综合成人91精品| 午夜视频在线在免费| 国色精品va在线观看免费视频 | 男人j进女人p免费视频| 亚洲av色影在线| 国产一区二区三区在线观看免费|