zoukankan      html  css  js  c++  java
  • SiteMesh的使用--笔记

      本博客是自己在学习和工作途中的积累与总结,仅供自己参考,也欢迎大家转载,转载时请注明出处。 

      http://www.cnblogs.com/king-xg/p/6472659.html

    Sitemesh 是一个网页布局和修饰的框架,基于 Servlet 中的 Filter,类似于 ASP.NET 中的‘母版页’技术。参考:百度百科,相关类似技术:Apache Tiles

     1. Maven项目,新建

     2. 引入sitemesh2.4.2.jar以及可能需要的server-api.jar,本人的运行环境是wildfly,所以需要引入

      

    <!-- sitemesh jar -->
    	<dependency>
    	    <groupId>opensymphony</groupId>
    	    <artifactId>sitemesh</artifactId>
    	    <version>2.4.2</version>
    	</dependency>
    	<!-- sitemesh jar -->
      	<dependency>
    	    <groupId>javax.servlet</groupId>
    	    <artifactId>javax.servlet-api</artifactId>
    	    <version>3.1.0</version>
    	</dependency>  
    

     3. web.xml中添加配置

    <!-- siteMesh 配置 -->
      <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>  
     <!-- siteMesh 配置 -->

    4. 并在web-info目录下添加decorators.xml的sitemesh的配置文件

    <?xml version="1.0" encoding="UTF-8" ?>
    <decorators defaultdir="/views/">  
     <!-- 不需要过滤的请求 -->  
     <excludes>  
      <pattern>/static/*</pattern>  
      <pattern>/remote/*</pattern>  
     </excludes>  
     <!-- 定义装饰器要过滤的页面 -->  
     <decorator name="default" page="default.jsp">  
      <pattern>/*</pattern>  
     </decorator>  
    </decorators>  

    注释: element:decorators 是根节点,defaultdir为绝对路径,此处表示webRoot(项目更目录)下的views文件夹下

        element:excludes,pattern表示不会拦截匹配以下pattern所对应的请求,pattern可配置多个

        element:decorator表示匹配pattern的请求均会被default.jsp所装饰,name作为该配置文件中的唯一标识。

     5. 在装饰页面引入,例如:default.jsp

    <%@ taglib prefix="sitemesh" uri="http://www.opensymphony.com/sitemesh/decorator" %>

    6. 在指定位置使用<sitemesh:body></sitemesh:body>,<sitemesh:title></sitemesh:title>,<sitemesh:head></sitemesh:head>....

     

  • 相关阅读:
    My first blog!
    Elasticsearch安装 + Head插件安装 + Bigdesk插件安装
    泛型-反射-注解
    JFinal自定义FreeMarker标签
    Hadoop集群中节点角色定义
    HBase
    MapReduce
    HDFS
    Hadoop基本概念
    HTTP浅析
  • 原文地址:https://www.cnblogs.com/king-xg/p/6472659.html
Copyright © 2011-2022 走看看