SiteMesh

本文详细介绍了如何在项目中使用SiteMesh实现页面布局,包括添加依赖、配置过滤器、设置装饰器及模板文件等步骤。

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

1.导入对SiteMesh.jar的依赖

<dependency>
      <groupId>org.sitemesh</groupId>
      <artifactId>sitemesh</artifactId>
      <version>3.0.0</version>
</dependency>

2.web.xml中配置过滤器

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

3.WEB-INF中配置文件decorators.xml

<!-- /WEB-INF/content/theme表示存放模板(主题)的文件夹 -->
<?xml version="1.0" encoding="UTF-8"?>
<decorators defaultdir="/WEB-INF/content/theme">
            <!-- name随意起 page主题网页 -->
    <decorator name="simple-theme" page="layout.jsp">
        <!-- 指的是所有网页都进行装饰 -->
        <pattern>/*</pattern>
    </decorator>
    <excludes>
    <!-- 表示静态资源不受影响,img表示静态资源文件夹 -->
        <pattern>/img/*</pattern>
    </excludes>
    <excludes>
        <!-- 表示除了这个网页 -->
        <pattern>/admin/home.action</pattern>
    </excludes>

</decorators>

4.模板jsp的设置,需要导入标签

<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="sitemesh-decorator" uri="http://www.opensymphony.com/sitemesh/decorator"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title><sitemesh-decorator:title/></title>
<!-- 头部也要导入,比如css之类的 -->
<sitemesh-decorator:head/>
</head>
<body>
    <h1>head head</h1>
    <!-- 导入body的部分 -->
    <sitemesh-decorator:body/>
    <h1>这是底部</h1>
</body>
</html>

 

转载于:https://www.cnblogs.com/itliucheng/p/4462263.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值