sitemesh
SiteMesh 是一個網頁佈局和修飾的框架,利用它可以將網頁的內容和頁面結構分離,以達到頁面結構共享的目的。
使用教材
1.POM文件
<dependency>
<groupId>opensymphony</groupId>
<artifactId>sitemesh</artifactId>
<version>2.4.2</version>
</dependency>
<dependency>
<groupId>org.sitemesh</groupId>
<artifactId>sitemesh</artifactId>
<version>3.0.1</version>
</dependency>
這是爲了引入sitemesh的包。
2.web.xml
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class>
<async-supported>true</async-supported>
</filter>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
這是在項目中做sitemesh的配置。
3.sitemesh的使用
在WEB-INF的路徑下建一個sitemesh.xml文件。
文件內容如下:
<?xml version="1.0" encoding="UTF-8"?>
<sitemesh>
<mapping path="/*" decorator="/WEB-INF/include/default.jsp"/>
</sitemesh>
這個文件裏面是指在所有頁面中都要加上default.jsp這個文件裏面的內容。
然後這裏的default.jsp和大家平時寫的jsp文件沒有任何的不同,你平時怎麼寫,這個也是怎麼寫的。
不過我這個裏面有一點不太一樣的是
<title><sitemesh:write property='title'/></title>
因爲我的每個頁面的title是不一樣的。
再給大家看一下我引用到了default.jsp的頁面寫的吧
<%@ page contentType="text/html;charset=UTF-8" %>
<!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>
是不是感覺這個裏面少了很多東西呢,這就是因爲sitemesh了。