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

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

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

    jinfeng_wang

    G-G-S,D-D-U!

    BlogJava 首頁 新隨筆 聯系 聚合 管理
      400 Posts :: 0 Stories :: 296 Comments :: 0 Trackbacks
    http://www.iocblog.net/static/2007/571.html

    安裝

    • 首先從sitemesh下載安裝包,這里使用的是2.2.1版本。
    • 創建一個Web應用程序,這里我創建一個名為myapp的Web應用程序;
    • 復制sitemesh-2.2.1.jar文件到{myapp}/WEB-INF/lib目錄下;
    • 編輯{myapp}/WEB-INF/web.xml文件
    <?xml version="1.0" encoding="UTF-8"?>

    <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
         version="2.4">
        <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>
       
        <session-config>
        <session-timeout>
            30
        </session-timeout>
        </session-config>
        <welcome-file-list>
        <welcome-file>
            index.jsp
        </welcome-file>
        </welcome-file-list>
    </web-app>

    添加藍色高亮部分。
    • 在{myapp}/WEB-INF/目錄下創建decorators.xml文件,并且輸入一下內容
    <?xml version="1.0" encoding="ISO-8859-1"?>

    <decorators defaultdir="/decorators">
        <decorator name="main" page="main.jsp">
            <pattern>/*</pattern>
        </decorator>

        <decorator name="panel" page="panel.jsp"/>
        <decorator name="printable" page="printable.jsp"/>
    </decorators>
    • 安裝完畢。

    例子1

    • 在{myapp}/WEB-INF/decorators.xml文件中添加以下decorator
    <decorator name="mydecorator1" page="mydecorator1.jsp">
            <pattern>/test1.jsp</pattern>
        </decorator>
    • 在{myapp}/decorators目錄下添加mydecorator1.jsp文件,內容如下:
    <%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>
    <html>
        <head>
            <title>My Site - <decorator:title default="Welcome!" /></title>
            <decorator:head />
        </head>
        <body>
            <decorator:body />
            <p>This message is in /decorators/mydecorator1.jsp</p>       
        </body>
    </html>
    • 在{myapp}目錄下添加test1.jsp文件,內容如下:
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>This is test1</title>
        </head>
        <body>
        <b>This is test1</b>
        </body>
    </html>

    • 打開瀏覽器,訪問http://localhost:8080/myapp/test1.jsp,將會出現一下內容:

    This is test1

    This message is in /decorators/mydecorator1.jsp


    例子2 (decorator:getProperty tag)

    有時候,我們期望修改頁面中某個有固定標記的片段,例如我們的jsp中有一個標記<mytag>...</mytag>,此時可以用如下方法實現:
    • 在{myapp}/WEB-INF/decorators.xml文件中添加以下decorator
    <decorator name="mydecorator2" page="mydecorator2.jsp">
            <pattern>/test2.jsp</pattern>
        </decorator>
    • 在{myapp}/decorators目錄下添加mydecorator2.jsp文件,內容如下:
    <%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>

    <html>
        <head>
            <title>My Site - <decorator:title default="Welcome!" /></title>
            <decorator:head />
        </head>

        <body>
            <decorator:body />

            <decorator:getProperty property="page.content1"/>
            <decorator:getProperty property="page.content2"/>
           
            <!-- do nothing -->
            <decorator:getProperty property="page.content3"/>
           
            <p>This message is in /decorators/mydecorator2.jsp</p>
        </body>
    </html>
    • 在{myapp}目錄下添加test2.jsp文件,內容如下:
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>This is test2</title>
        </head>
       
        <body>
        <b>This is test2</b>
        <b>Use &lt;decorator:getProperty&gt; tag</b>
       
        <content tag="content1"><p>This is content1</p></content>
        <content tag="content2"><p>This is content2</p></content>
        <content tag="content4"><p>This is content4, it shouldn't be display</p></content>
        </body>
    </html>
    • 打開瀏覽器,訪問http://localhost:8080/myapp/test2.jsp,將會出現一下內容:

    This is test2

    Use <decorator:getProperty> tag

    This is content1

    This is content2

    This message is in /decorators/mydecorator2.jsp

    例子3 (page:applyDecorator tag)

    • 在{myapp}/WEB-INF/decorators.xml文件中添加以下decorator
        <decorator name="mydecorator3" page="mydecorator3.jsp">
            <pattern>/test3.jsp</pattern>
        </decorator>
        
        <decorator name="mydecorator31" page="mydecorator31.jsp">
        </decorator>
    • 在{myapp}/decorators目錄下添加mydecorator3.jsp文件,內容如下:
    <%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>
    <%@ taglib uri="http://www.opensymphony.com/sitemesh/page" prefix="page" %>
    <html>
        <head>
            <title>My Site - <decorator:title default="Welcome!" /></title>
            <decorator:head />
        </head>

        <body>
            <decorator:body />

            <page:applyDecorator name="mydecorator31">
                <content tag="content1"><p>This is content1</p></content>
                <content tag="content2"><p>This is content2</p></content>
            </page:applyDecorator>
        </body>
    </html>
    在{myapp}/decorators目錄下添加mydecorator31.jsp文件,內容如下:
    <%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>
    <%@ taglib uri="http://www.opensymphony.com/sitemesh/page" prefix="page" %>

    <p><i>begin</i></>
    <decorator:getProperty property="page.content1"/>
    <decorator:getProperty property="page.content2"/>
    <p><i>end</i></>
    • 在{myapp}目錄下添加test3.jsp文件,內容如下:
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>This is test3</title>
        </head>
       
        <body>
        <b>This is test3</b>
        <b>Use &lt;page:applyDecorator&gt; tag</b>
        </body>
    </html>
    注意:相對于例子2,這里已經沒有了<content tag="XXX"/>標簽。
    • 打開瀏覽器,訪問http://localhost:8080/myapp/test3.jsp,將會出現一下內容:

    This is test3

    Use <page:applyDecorator> tag

    begin

    This is content1

    This is content2

    end

    這里,我在mydecorator3.jsp中應用了mydecorator31.jsp的的decorator,并且將原來在test2.jsp中的 <content />標簽復制到mydecorator3.jsp中,此時對于<content tag="xxx"/>的標簽將會由mydecorator31.jsp了裝飾。

    例子4 (page:param tag)

    • 在{myapp}/WEB-INF/decorators.xml文件中添加以下decorator
        <decorator name="mydecorator4" page="mydecorator4.jsp">
            <pattern>/test4.jsp</pattern>
        </decorator>
        
        <decorator name="mydecorator41" page="mydecorator41.jsp">
        </decorator>
    • 在{myapp}/decorators目錄下添加mydecorator4.jsp文件,內容如下:
    <%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>
    <%@ taglib uri="http://www.opensymphony.com/sitemesh/page" prefix="page" %>

    <html>
        <head>
            <title>My Site - <decorator:title default="Welcome!" /></title>
            <decorator:head />
        </head>

        <body>
            <decorator:body />
            <page:applyDecorator name="mydecorator41" >
                <content tag="content1"><p>This is content1</p></content>
                <content tag="content2"><p>This is content2</p></content>
                <page:param name="page.content1"><p>This content1 has been replaced</p></page:param>
            </page:applyDecorator>
        </body>
    </html>
    在{myapp}/decorators目錄下添加mydecorator41.jsp文件,內容如下:
    <%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>
    <%@ taglib uri="http://www.opensymphony.com/sitemesh/page" prefix="page" %>

    <p><i>begin</i></>
    <decorator:getProperty property="page.content1"/>
    <decorator:getProperty property="page.content2"/>
    <p><i>end</i></>
    • 在{myapp}目錄下添加test4.jsp文件,內容如下:
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>This is test4</title>
        </head>
       
        <body>
        <b>This is test4</b>
        <b>Use &lt;page:param&gt; tag</b>
        </body>
    </html> 
    • 打開瀏覽器,訪問http://localhost:8080/myapp/test4.jsp,將會出現一下內容:

    This is test4

    Use <page:param> tag

    begin

    This content1 has been replaced

    This is content2

    end

    這里,我在mydecorator4.jsp中應用了mydecorator41.jsp的的decorator,并且添加了<page:param name="page.content1">標簽,那么此時頁面上將會用<page:param>標簽中的內容替換原來在<decorator:getProperty property="page.content1"/>中的內容,因此頁面將不在This is content1”而顯示This content1 has been replaced”。


    posted on 2008-03-07 16:28 jinfeng_wang 閱讀(741) 評論(0)  編輯  收藏 所屬分類: javaZZ
    主站蜘蛛池模板: 玖玖在线免费视频| 免费看男人j放进女人j免费看| 国产精品视频免费| 久久青青草原亚洲av无码app| 成人A毛片免费观看网站| 亚洲精品无码久久不卡| a高清免费毛片久久| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 国产午夜免费高清久久影院| 国产精品亚洲产品一区二区三区 | 一本色道久久88—综合亚洲精品 | 最近最新高清免费中文字幕| 亚洲一区二区影院| 国产曰批免费视频播放免费s| 亚洲无限乱码一二三四区| 国产男女爽爽爽爽爽免费视频| 亚洲大香人伊一本线| 亚洲第一成年免费网站| 亚洲色在线无码国产精品不卡| 日韩视频免费在线| 新最免费影视大全在线播放| 中文亚洲成a人片在线观看| a毛看片免费观看视频| 亚洲国产精品久久久久婷婷软件| 亚洲大片免费观看| 亚洲人成色777777老人头| 无码专区一va亚洲v专区在线 | 日韩精品无码永久免费网站| 亚洲日韩国产精品乱| 免费看搞黄视频网站| 亚洲人成人77777网站不卡 | 久久久久久久亚洲精品| 精品四虎免费观看国产高清午夜| 亚洲欧洲国产成人精品| 国产精品色午夜免费视频| 久99久无码精品视频免费播放| 亚洲日本香蕉视频观看视频| 四虎影视永久免费观看| 久久青草精品38国产免费| 亚洲人成色77777在线观看| 亚洲人成色7777在线观看|