1. 程式人生 > >SiteMesh 網頁模板外掛應用參考

SiteMesh 網頁模板外掛應用參考

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

<?

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、編寫模板頁面

<%-- 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過濾器

<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>