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