sitemesh

本文详细介绍了如何使用SiteMesh框架在JSP中实现页面布局和装饰的分离,通过引入jar包、配置web.xml、创建装饰模板、配置映射文件等步骤,实现了动态内容与静态外观的高效分离,提升网站开发效率。

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

sitemesh
OS(OpenSymphony)的SiteMesh是一个用来在JSP中实现页面布局和装饰(layout and decoration)的框架组件,能够帮助网站开发人员较容易实现页面中动态内容和静态装饰外观的分离。

[img]http://www.sitemesh.org/overview.gif[/img]

1.引入jar包
[url]https://github.com/sitemesh/sitemesh3/downloads[/url]
2.配置web.xml

<web-app>

<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>

</web-app>

3.创建装饰模板,包含内容的占位符<title>,<head>,<body>

<html>
<head>
<title>SiteMesh example: <sitemesh:write property='title'/></title>
<style type='text/css'>
/* Some CSS */
body { font-family: arial, sans-serif; background-color: #ffffcc; }
h1, h2, h3, h4 { text-align: center; background-color: #ccffcc; border-top: 1px solid #66ff66; }
.mainBody { padding: 10px; border: 1px solid #555555; }
.disclaimer { text-align: center; border-top: 1px solid #cccccc; margin-top: 40px; color: #666666; font-size: smaller; }
</style>
<sitemesh:write property='head'/>
</head>
<body>

<h1 class='title'>SiteMesh example site: <sitemesh:write property='title'/></h1>

<div class='mainBody'>
<sitemesh:write property='body'/>
</div>

<div class='disclaimer'>Site disclaimer. This is an example.</div>

</body>
</html>

4.配置映射sitemesh3.xml

<sitemesh>
<!-- 哪些路径应用哪个装饰器,可以用*进行通配 -->
<mapping path="/*" decorator="/decorator.html"/>
<!-- 排除那些路径 -->
<mapping path="/brochures/*" exclue="true"/>
</sitemesh>

5.创建一个页面

<html>
<head>
<title>Hello World</title>
<meta name='description' content='A simple page'>
</head>
<body>
<p>Hello <strong>world</strong>!</p>
</body>
</html>

6.结果

<html>
<head>
<title>SiteMesh example: Hello World</title>
<style type='text/css'>
/* Some CSS */
body { font-family: arial, sans-serif; background-color: #ffffcc; }
h1, h2, h3, h4 { text-align: center; background-color: #ccffcc; border-top: 1px solid #66ff66; }
.mainBody { padding: 10px; border: 1px solid #555555; }
.disclaimer { text-align: center; border-top: 1px solid #cccccc; margin-top: 40px; color: #666666; font-size: smaller; }
</style>
<meta name='description' content='A simple page'>
</head>
<body>

<h1 class='title'>SiteMesh example site: Hello World</h1>

<div class='mainBody'>
<p>Hello <strong>world</strong>!</p>
</div>

<div class='disclaimer'>Site disclaimer. This is an example.</div>

</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值