1.在pom.xml加入坐标
<!-- sitemesh 依赖,前端 -->
<dependency>
<groupId>opensymphony</groupId>
<artifactId>sitemesh</artifactId>
<version>2.4.2</version>
</dependency>
2.在web.xml中添加
<!--添加sitemesh2支持 -->
<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>
3.在WEB-INF下添加decorators.xml文件,配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<!-- 装饰器配置,装饰器或组件默认路径 -->
<decorators defaultdir="/WEB-INF/jsp/decorators">
<!-- 不装饰的URL -->
<excludes>
<pattern>/login</pattern>
</excludes>
<!-- 主页装饰器组件 -->
<decorator name="header" page="header.jsp" />
<decorator name="footer" page="footer.jsp" />
<!-- 主页装饰器 -->
<decorator name="main" page="main.jsp">
<pattern>/*</pattern>
</decorator>
</decorators>
4.在jsp主文件中添加
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator"%>
<!--。。。。省略其它代码-->
<body class="nav-md">
<page:applyDecorator name="header" />
<div class="right_col" role="main">
<!--主体填充区 -->
<decorator:getProperty property="page.body" />
</div>
<page:applyDecorator name="footer" />
</body>
<!--。。。。省略其它代码-->
5.其它使用
<%@ page pageEncoding="utf-8"%>
<title>主页</title>
<content tag="breadcrumb">
<li>主页</li>
</content>
<content tag="body"> <%-- 面板主体 --%>
<img src="${APP_PATH}/static/images/welcome.gif" width="210"
height="70" />
</content>