• sitemesh 使用方法


    一、简介

      SiteMesh是一个网页布局和修饰的框架,利用它可以将网页的内容和页面结构分离,以达到页面结构共享的目的。
      它能通过创建一个包装对象,也就是装饰来包裹的对象。尽管它是由Java语言来实现的,但是它能与其他Web应用很好的集成。

    二、使用步骤

    1、下载sitemesh jar包

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

    2、把sitemesh jar 导入项目中

    创建decorators.xml文件:

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- defaultdir 是模板所在的文件夹路径 -->
    <decorators defaultdir="/layouts">
    
        <!-- 下面是过滤css和js文件,按实际情况写 -->
        <excludes>
            <pattern>/assets/*</pattern>
        </excludes>
    
        <!-- /* 所有页面,按模板 phone_template.jsp 来修饰 -->
        <decorator name="phone" page="phone_template.jsp">
            <pattern>/*</pattern>
        </decorator>
    
    </decorators>

    web.xml文件配置

        <!-- 定义过滤器-->
        <filter>
            <!-- 定义过滤器的实现类 -->
            <filter-name>sitemesh</filter-name>
            <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
        </filter>
    
        <!--  定义过滤器拦截URL地址 -->
        <filter-mapping>
            <!-- 过滤器的名称 -->
            <filter-name>sitemesh</filter-name>
            <!-- 过滤器负责拦截的URL,如下定义会拦截所有  -->
            <url-pattern>/*</url-pattern>
        </filter-mapping>

     模板(phone_template.jsp):

    <%@ taglib prefix="sitemesh" uri="http://www.opensymphony.com/sitemesh/decorator" %>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <!doctype html>
    <html lang="en">
    <head>
        <!--  sitemesh:title 的作用是,将要修饰的页面的title引入 -->
        <title><sitemesh:title/></title>
        <!-- 不用在意下面的样式引入  -->
        <link href="/js_css/css/bootstrap.css" rel="stylesheet">
        <link href="/js_css/css/offcanvas.css" rel="stylesheet">
    </head>
    
    <body class="bg-light">
    
        <%@include file="phone_head_nva.jsp"%>
    
        <%@include file="phone_body_nva.jsp"%>
    
    
        <main role="main" class="container">
                <!--  这里会把要修饰的页面的body部分引入 -->
                <sitemesh:body></sitemesh:body>
        </main>
    
        <%@include file="phone_footer.jsp"%>
    
    </body>
    </html>

    总之,定义模板的作用是,让指定的网页用模板修饰,比如模板的上面有一个导航栏,则被模板修饰的网页都有导航栏。

  • 相关阅读:
    ES自身支持容灾异地容灾么?生产环境如何实施?
    Redis集群详解
    原生js实现jquery的ajax
    用原生js实现jquery的一些方法
    原生javascript的一些常用方法
    原生javascript
    理解和熟练运用call和apply
    做项目过程中的css reset
    深入理解javascript编程中的同步和异步
    history.back(-1)和history.go(-1)的区别
  • 原文地址:https://www.cnblogs.com/ldl326308/p/9509339.html
Copyright © 2020-2023  润新知