Sitemesh-创建一致的页面布局和外观

初步使用资料
http://www.cnblogs.com/mailingfeng/archive/2011/12/21/2296105.html

1、Sitemesh3.0的配置文件
跟2.X版本不同,siteMesh简化了配置,这里只需要在/WEB-INF目录下建立一个sitemesh3.xml文件

2、搭建SiteMesh3环境
下载sitemesh3.0
将其中disk文件夹下的sitemesh-3.0-alpha-2.jar导入/WEB-INF/lib目录下


3、建立装饰页(decorator.jsp)

4、web.xml的配置
这里不再需要像2.X版本去配置taglib,所以是相当地简化的

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>SiteMesh3TestProject</display-name>
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

5、要实现SiteMesh过滤不装饰页面,需要做两方面的设置sitemesh3.xml
<?xml version="1.0" encoding="UTF-8"?>
<sitemesh>
<!-- 默认装饰器,当下面的路径都不匹配时,启用该装饰器进行装饰-->
<mapping decorator="/pages/decorators/template.jsp"/>

<!-- 对不同的路径,启用不同的装饰器 -->
<mapping path="/pages/login/*" decorator="/pages/decorators/loginTemplate.jsp"/>

<!-- 排除,不进行装饰的路径 -->
<mapping path="/pages/version/*" exclue="true"/>

<!-- 对同一路径,启用多个装饰器 -->
<mapping>
<path>/articles/*</path>
<decorator>/decorators/article.html</decorator>
<decorator>/decorators/two-page-layout.html</decorator>
<decorator>/decorators/common.html</decorator>
</mapping>
</sitemesh>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值