1.maven 配置
<dependency>
<groupId>opensymphony</groupId>
<artifactId>sitemesh</artifactId>
<version>2.4.2</version>
</dependency>
2.web.xml 配置
<filter>
<filter-name>siteMesh</filter-name>
<filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>siteMesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
3.添加decorators.xml
添加路径为:WEB-INF/目录下
<?xml version="1.0" encoding="UTF-8"?>
<decorators>
<decorator name="default-theme" page="/default-theme.jsp">
//要渲染的url的请求地址
<pattern>/home/*</pattern>
</decorator>
</decorators>
4.添加默认样式文件
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!-- 添加上taglib 库 -->
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>
<%@ taglib uri="http://www.opensymphony.com/sitemesh/page" prefix="page" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>
<!-- 如果被渲染的页面中添加了title 就用,没有就用 default 中配置的 -->
<decorator:title default="ls" />
<title>
<%@ include file="/common/head.jsp"%>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<!-- Main content -->
<section class="content">
<!-- 被渲染的页面,显示的地方 -->
<decorator:body></decorator:body>
</section>
<!-- /.Left col -->
</body>
</html>
5.添加要渲染的文件
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- 在要渲染的页面中添加 title 为加载到 样式页面上去 -->
<title>我的渲染页面</title>
</head>
<body class="hold-transition skin-blue sidebar-mini">
hello world!
</body>
</html>
6.测试连接地址就可以了。