SiteMesh3使用介绍及配置方法

1.简单介绍

Sitemesh 是一个网页布局和修饰的框架,基于 Servlet 中的 Filter,类似于 ASP.NET 中的‘母版页’技术。参考:百度百科


官网:http://wiki.sitemesh.org/wiki/display/sitemesh/Home 。

2.sitemesh3 相关jar包下载

3.sitemesh3配置文件进行配置(对指定访问请求的进行修饰) 

    
原码如下:
<?xml version="1.0" encoding="UTF-8"?>
<sitemesh>
<!-- 指明满足“/*”的页面,将被“/WEB-INF/views/decorators/decorator.html”所装饰 -->
<mapping path="/*" decorator="/platform/decorators/decorator.jsp"/>
<!-- 指明满足“/exclude.jsp*”的页面,将被排除,不被装饰 -->
<mapping path="/exclude.jsp" exclue="true"/>
</sitemesh>

4.web.xml中对sitemesh3进行配置(过滤器) 


原码:
<!-- sitemesh 框架渲染器 -->
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class>
<!-- <filter-class>com.zhjy.web.sitemesh.OpsConfigurableSiteMeshFilter</filter-class> -->
</filter>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>  
      <dispatcher>REQUEST</dispatcher>   
</filter-mapping>

5.准备两个界面:修饰界面(decorator.jsp)、被修饰界面(demo.jsp即需要展示的界面) 

decorator.jsp如下:


<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page language="java" import="java.util.*"%>  
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><sitemesh:write property='title'/></title>
<sitemesh:write property='head' />
</head>
<body>
<header>header</header>
     <hr />
     demo.html的title将被填充到这儿:
     <sitemesh:write property='title' /><br />
     demo.html的body将被填充到这儿:
     <sitemesh:write property='body' />
     <hr />
     <footer>footer</footer>
</body>
</html>

demo.jsp如下:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page language="java" import="java.util.*"%>  
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>内容页的标题</title>
</head>
<body>
内容页的body部分
</body>
</html>

6.运行效果
请求地址:











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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值