sitemesh页面框架demo

一、在WEB-INF下面定义文件decorators.xml,内容如下:

<?xml version="1.0" encoding="utf-8"?>  

<decorators defaultdir="/WEB-INF/layouts/">  
    <!-- 此处用来定义不需要过滤的页面 -->  
    <excludes>  
		<pattern>/index.jsp</pattern>
    </excludes>  
 <!-- 用来定义装饰器要过滤的页面 -->  
    <decorator name="default" page="default.jsp">  
        <pattern>/*</pattern>
    </decorator>  
</decorators>  


 

二、定义装饰页:(/WEB-INF/layouts/default.jsp),内容:

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib prefix="sitemesh" uri="http://www.opensymphony.com/sitemesh/decorator" %>
<!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:title default="sitemesh title"></sitemesh:title> </title>
<sitemesh:head/>
</head>
<body>
<h2>SiteMesh装饰header</h2><br/>
<sitemesh:body/>
<h2>SiteMesh装饰footer</h2> <br/>
</body>
</html>


 

三、web.xml增加内容为:

<filter>
  	<filter-name>sitemeshFilter</filter-name>
  	<filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
  </filter>
  
  <filter-mapping>
  	<filter-name>sitemeshFilter</filter-name>
  	<url-pattern>/*</url-pattern>
  </filter-mapping>


 

四、需要的sitemesh依赖:

<dependency>
				<groupId>opensymphony</groupId>
				<artifactId>sitemesh</artifactId> <!-- 页面装饰框架 -->
				<version>2.4.2</version>
			</dependency>


结果就是,没有过滤的页面都会加上,装饰页的内容

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值