一、在WEB-INF下面定义文件decorators.xml,内容如下:
<?xml version="1.0" encoding="utf-8"?>
<decorators defaultdir="/WEB-INF/layouts/">
<!-- 此处用来定义不需要过滤的页面 -->
<excludes>
<pattern>/index.jsp</pattern>
</excludes>
<!-- 用来定义装饰器要过滤的页面 -->
<decorator name="default" page="default.jsp">
<pattern>/*</pattern>
</decorator>
</decorators>
二、定义装饰页:(/WEB-INF/layouts/default.jsp),内容:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib prefix="sitemesh" uri="http://www.opensymphony.com/sitemesh/decorator" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><sitemesh:title default="sitemesh title"></sitemesh:title> </title>
<sitemesh:head/>
</head>
<body>
<h2>SiteMesh装饰header</h2><br/>
<sitemesh:body/>
<h2>SiteMesh装饰footer</h2> <br/>
</body>
</html>
三、web.xml增加内容为:
<filter>
<filter-name>sitemeshFilter</filter-name>
<filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemeshFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
四、需要的sitemesh依赖:
<dependency>
<groupId>opensymphony</groupId>
<artifactId>sitemesh</artifactId> <!-- 页面装饰框架 -->
<version>2.4.2</version>
</dependency>
结果就是,没有过滤的页面都会加上,装饰页的内容