1、maven依赖

<!-- https://mvnrepository.com/artifact/opensymphony/sitemesh -->

<dependency>

<groupId>opensymphony</groupId>

<artifactId>sitemesh</artifactId>

<version>2.4.2</version>

</dependency>

 

2、web-inf下添加装饰配置文件:decorators.xml

SiteMesh 网页模板插件应用参考

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

 

<decorators defaultdir="/jsp">

<excludes>

<pattern>/exclude.jsp</pattern>

<pattern>/exclude/*</pattern>

</excludes>

<decorator name="main" page="main.jsp">

<pattern>/*</pattern>

</decorator>

</decorators>

 

3、编写模板页面

SiteMesh 网页模板插件应用参考

<%-- Created by IntelliJ IDEA. User By: Mr Chen 下午 12:31 --%>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

<%@ taglib prefix="decorator" uri="http://www.opensymphony.com/sitemesh/decorator" %>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!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><decorator:title default="欢迎使用用户管理系统" /></title>

<decorator:head />

</head>

<body>

<table width="700" align="center" border="0">

<tr>

<td align="center" ><h1><decorator:title /></h1></td>

</tr>

</table>

<hr />

<decorator:body />

</body>

</html>

 

4、web.xml文件中添加siteMesh过滤器

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>

相关文章:

  • 2022-01-14
  • 2021-11-17
  • 2021-05-23
  • 2022-12-23
  • 2021-11-15
  • 2021-07-23
猜你喜欢
  • 2022-01-24
  • 2021-05-23
  • 2022-12-23
  • 2022-03-06
  • 2021-05-22
  • 2022-02-24
  • 2022-02-20
相关资源
相似解决方案