SiteMesh3入门教程

本文介绍SiteMesh3,一个用于网页布局和修饰的框架,它能实现网页内容与页面结构的分离,便于共享页面结构。通过详细说明配置依赖、web.xml文件配置及sitemesh3.xml文件的使用,帮助开发者轻松掌握SiteMesh3的基本应用。

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

SiteMesh3入门教程

一,SiteMesh简介

SiteMesh 是一个网页布局和修饰的框架,利用它可以将网页的内容和页面结构分离,以达到页面结构共享的目的。


SiteMesh是基于Servlet的filter的,即过滤流。它是通过截取response,并进行装饰后再交付给客户。

其中涉及到两个名词: 装饰页面(decorator page)和 "被装饰页面(Content page)" , 即 SiteMesh通过对Content Page的装饰,最终得到页面布局和外观一致的页面,并返回给客户

sitemesh运行环境需要:servlet, JDK 。


以上来自百度百科。

二,基本配置


请注意,本文使用的sitemesh版本为sitemesh3。


依赖


1
2
3
4
5
< dependency >
     < groupId >org.sitemesh</ groupId >
     < artifactId >sitemesh</ artifactId >
     < version >3.0.0</ version >
</ dependency >


web.xml配置


1
2
3
4
5
6
7
8
9
<!-- sitemesh配置 -->
< filter >
     < filter-name >sitemesh</ filter-name >
     < filter-class >org.sitemesh.config.ConfigurableSiteMeshFilter</ filter-class >
</ filter >
< filter-mapping >
     < filter-name >sitemesh</ filter-name >
     < url-pattern >/*</ url-pattern >
</ filter-mapping >


sitemesh3.xml


将sitemesh3.xml保存到 src\main\webapp\WEB-INF\sitemesh3.xml 路径下(我用的是maven,如果你不是maven,应该放到WEB-INF下)。


1
2
3
4
5
6
7
<? xml  version = "1.0"  encoding = "UTF-8" ?>
< sitemesh >
     <!-- 指明满足“/*”的页面,将被“/WEB-INF/views/decorators/decorator.html”所装饰 -->
     < mapping  path = "/*"  decorator = "/WEB-INF/views/layouts/main.jsp"  />
     <!-- 指明满足“/exclude.jsp*”的页面,将被排除,不被装饰 -->
     < mapping  path = "/login"  exclue = "true"  />
</ sitemesh >


三,使用

1
2
3
4
5
6
7
8
9
< html >
   < head >
     < title >< sitemesh:write  property = 'title' /></ title >
     < sitemesh:write  property = 'head' />
   </ head >
   < body >
     < sitemesh:write  property = 'body' />
   </ body >
</ html >


参考链接

http://wiki.sitemesh.org/wiki/display/sitemesh3/Getting+Started+with+SiteMesh+3


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值