使用sitemesh3装饰页面

本文介绍如何在项目中使用Sitemesh3进行页面布局整合,包括Maven依赖配置、项目结构设置、Web.xml中filter的添加、sitemesh3.xml的配置细节及装饰页面的标签使用方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、使用maven引包

<dependency>
    <groupId>org.sitemesh</groupId>
    <artifactId>sitemesh</artifactId>
    <version>${org.sitemesh.version}</version>
</dependency>

二、项目结构,在WEB-INF中新建sitemesh3.xml和一个装饰页面
这里写图片描述

三、在web.xml中添加filter

<!-- sitemesh过滤器start -->
    <filter>  
        <filter-name>sitemesh</filter-name>  
        <filter-class>  
            org.sitemesh.config.ConfigurableSiteMeshFilter 
        </filter-class>  
    </filter>  
    <filter-mapping>
        <filter-name>sitemesh</filter-name>  
        <url-pattern>/pages/*</url-pattern>  
    </filter-mapping> 
    <!-- sitemesh过滤器end -->

四、sitemesh3.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<sitemesh>
    <!-- 指明页面,将被装饰 -->
    <mapping path="/pages/system/*" decorator="/WEB-INF/views/decorators/main.jsp" />

    <!-- 指明页面,将被排除,不被装饰 -->
    <mapping path="/pages/system/login*" exclue="true" />
    <mapping path="/pages/error/*" exclue="true" />
</sitemesh>

五、装饰页面中的标签使用

<!-- 从被装饰页面获取title标签内容--> 
<title>后台管理系统 - <sitemesh:write property='title'  /></title>
<!-- 从被装饰页面获取head标签内容 -->
<sitemesh:write property='head' />
<!-- 从被装饰页面获取body标签内容 -->
<sitemesh:write property='body' />

和sitemesh2不同,sitemesh3还有可以自定义标签,所以装饰页面就不用引入taglib了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值