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> 

猜你喜欢

转载自oliven102201.iteye.com/blog/2119129
今日推荐