sitemesh 使用方法

jar包下载官网:http://wiki.sitemesh.org/wiki/display/sitemesh/Home

把sitemesh jar 导入项目中

创建decorators.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<decorators defaultdir="/layouts">

    <!-- 定义不过滤的页面,即排除页面 -->
    <excludes>
        <pattern>/assets/*</pattern>
    </excludes>

    <!--  定义要装饰的页面  -->
    <decorator name="book" page="book_Main.jsp">
        <pattern>/*</pattern>
    </decorator>
</decorators>

web.xml文件配置

    <!-- 引入setemesh 过滤器  -->
    <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>

项目文件结构:

 自定义模板,并且进行分离

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

<!doctype html>
<html lang="en">
<head>
    <title><sitemesh:title /></title>

    <%@include file="book_top_res.jsp"%>

</head>

<body>

    <%@include file="book_top_nva.jsp"%>

<div class="container-fluid">
    <div class="row">

        <%@include file="book_body_nva.jsp"%>

        <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
            <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pb-2 mb-3 border-bottom">
                <p class="h4">HELLO BOOTSTRAP!!!</p>
                <div class="btn-toolbar mb-2 mb-md-0">
                    <div class="btn-group mr-2">
                        <button class="btn btn-sm btn-outline-secondary">Share</button>
                        <button class="btn btn-sm btn-outline-secondary">Export</button>
                    </div>
                    <button class="btn btn-sm btn-outline-secondary dropdown-toggle">
                        <span data-feather="calendar"></span>
                        This week
                    </button>
                </div>
            </div>
            
                <!-- 引入要修饰的网页的body内容 -->
                <sitemesh:body></sitemesh:body>

            </div>
        </main>
    </div>
</div>

<%@include file="book_footer.jsp"%>

</body>
</html>

猜你喜欢

转载自www.cnblogs.com/ldl326308/p/9509339.html