SiteMesh3的基本使用

Sitemesh是一个网页布局和修饰的开源框架,利用它可以将网页的内容和页面结构分离,用以达到页面结构共享的目的,类似于ASP.NET的“母版页”技术。
Sitemesh是基于servlet的filter过滤器实现。
Sitemesh是通过拦截response,并进行修饰后再发送给客户端浏览器。

1.导入SiteMesh3架包


2.编写母版页:
在WebContent文件夹下创建一个新文件夹如:decorators
在新文件夹下创建母版页:decorator.jsp

如:给内容页加上水平分割线
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- 将装饰页面标题替换为内容页面标题 -->
<title><sitemesh:write property="title"/></title>
</head>
<body>    
    <hr>
    <!-- 添加进入内容页面的内容 -->
    <sitemesh:write property="body"/>
    <hr>
</body>
</html>

 

3.编写内容页:
在WebContent文件夹下新建jsp文件:Context.jsp

如:
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>测试内容页面标题</title>
</head>
<body>
    <h1>这是内容页面</h1>
</body>
</html>

 

4.添加web.xml文件配置:
  <!-- 配置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>


5.WEB-ING文件夹下新建sitemesh3.xml配置文件(名字有严格要求)

配置:
<?xml version="1.0" encoding="UTF-8"?>
<sitemesh>
    <!-- 配置被装饰页面、母版页 -->
    <mapping path="*" decorator="/decorators/decorator.jsp"/>
    <!-- 配置不被装饰页面 -->
    <mapping path="/Goods.jsp" exclue="true"/>
</sitemesh>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值