sitemesh配置

sitemesh是一个装饰页面的插件。它会拦截页面的html代码里的title,header,body。这样它就可以将一些公共的信息插入进去。起到了类似于include的作用。但它不会侵入代码。

官方网站:http://www.opensymphony.com/sitemesh/

 

SiteMesh - 安装和配置

siteMesh的配置相当简单.

 

  • 拷贝 sitemesh-2.4.1.jar [web-app]/WEB-INF/lib .
  • 新建文件到 [web-app]/WEB-INF/decorators.xml ,它包含如下内容:
    <decorators>
    </decorators>
  • 添加如下信息到 [web-app]/WEB-INF/web.xml <web-app> 标签中:
    <filter>

    <filter-name>sitemesh
    </filter-name>

    <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter
    </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>





 

附一个  decorators.xml

 

<!-- 定义装饰器页面的文件路径/decorators ,它会去/decorators下面找装饰器面页 -->
<decorators defaultdir="/decorators">
    <!-- 定义一个装饰器,pattern里面的文件都会被装饰器处理 -->
    <decorator name="main" page="main.jsp">
        <pattern>/buyer/*.jsp</pattern>

        <pattern>/remit/*.action</pattern>
    </decorator>
    <!-- 定义一些不需要装饰器处理的页面或aciton-->
    <excludes>

        <pattern>/buyer/index.jsp</pattern>
        <pattern>/batchQueryAccountDetail.action</pattern>   

     </excludes>
   
</decorators>

 

 

建立一个装饰器面页/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>

建立一个的被装饰页面 /index.jsp(内容页面)

<%@ page contentType="text/html; charset=GBK"%>
<html>
<head>
<title>Agent Test</title>
</head>
<body>
<p>本页只有一句,就是本句.</p>
</body>
</html>

结果页面:

<html
>
<head >
<title >
Agent Test
</title >
</head >
<body onclick ="sfdsf" >
sitemesh的例子<hr >
<p >本页只有一句,就是本句.</p >
<hr >chen56@msn.com
</body >
</html >











 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值