數(shù)據(jù)加載中……
          使用sitemesh建立復(fù)合視圖1
          簡介:
          sitemesh應(yīng)用Decorator模式,用filter截取request和response,把頁面組件head,content,banner結(jié)合為一個完整的視圖。通常我們都是用include標(biāo)簽在每個jsp頁面中來不斷的包含各種header, stylesheet, scripts and footer,現(xiàn)在,在sitemesh的幫助下,我們可以開心的刪掉他們了。如下圖,你想輕松的達(dá)到復(fù)合視圖模式,那末看完本文吧。

           

          hello sitemesh:
          1. 在WEB-INF/web.xml中copy以下filter的定義:
            <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>
                                        

          2. copy所需jar和dtd文件至相應(yīng)目錄,訪問opensymphony.sourceforge.net的cvs以獲取sitemesh最新版本。
            sitemesh.jar WEB-INF/lib
            sitemesh-decorator.tld WEB-INF
            sitemesh-page.tld WEB-INF

          3. 建立WEB-INF/decorators.xml描述各裝飾器頁面(可仿照sitemesh例子)。
            <decorators defaultdir="/_decorators">
                                        <decorator name="main" page="main.jsp">
                                        <pattern>*</pattern>
                                        </decorator>
                                        </decorators>



          4. 建立裝飾器頁面 /_decorators/main.jsp
            <%@ page contentType="text/html; charset=GBK"%>
                                        <%@ taglib uri="sitemesh-decorator" prefix="decorator" %>
                                        <html>
                                        <head>
                                        <title><decorator:title default="裝飾器頁面..." /></title>
                                        <decorator:head />
                                        </head>
                                        <body>
                                        sitemesh的例子<hr>
                                        <decorator:body />
                                        <hr>chen56@msn.com
                                        </body>
                                        </html>
                                        


          5. 建立一個的被裝飾頁面 /index.jsp(內(nèi)容頁面)
            <%@ page contentType="text/html; charset=GBK"%>
                                        <html>
                                        <head>
                                        <title>Agent Test</title>
                                        </head>
                                        <body>
                                        <p>本頁只有一句,就是本句.</p>
                                        </body>
                                        </html>

          最后訪問index.jsp,將生成如下頁面:

          而且,所有的頁面也會如同index.jsp一樣,被sitemesh的filter使用裝飾模式修改成如上圖般模樣,卻不用再使用include標(biāo)簽。

          posted on 2009-10-26 12:50 mingruofei 閱讀(65) 評論(0)  編輯  收藏


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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 城固县| 从江县| 屏山县| 淮安市| 梨树县| 溆浦县| 信丰县| 墨竹工卡县| 台安县| 昭觉县| 同德县| 肃宁县| 郯城县| 志丹县| 雅安市| 万州区| 福贡县| 宁乡县| 开封县| 海阳市| 阜阳市| 石柱| 会泽县| 应城市| 孙吴县| 中西区| 井研县| 隆尧县| 文登市| 鄂温| 舒城县| 华蓥市| 晋城| 万宁市| 佛学| 开鲁县| 虞城县| 崇阳县| 中山市| 双峰县| 鄱阳县|