JSP学习笔记(四十三):sitemesh的配置及使用

下载sitemesh

官方下载地址:http://www.opensymphony.com/sitemesh/download.action

 

配置sitemesh

1.修改web.xml,完整内容为:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation
="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
>
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>
com.opensymphony.module.sitemesh.filter.PageFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

 

在WebRoot/WEB-INF/目录下新建文件decorators.xml,内容为:

<?xml version="1.0" encoding="ISO-8859-1"?>
<decorators defaultdir="/decorators">
<decorator name="main" page="main.jsp">
<pattern>/*</pattern>
</decorator>
</decorators>

 

在WebRoot/decorators/目录下新建文件main.jsp,内容为:


<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator"
prefix
="decorator"%>
<%@ taglib uri="http://www.opensymphony.com/sitemesh/page" prefix="page"%>
<!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=GB2312">
<title>Insert title here</title>
</head>
<body>&lt;&gt;
<html>
<head>
<title>My Site - <decorator:title default="Welcome!" />
</title>
<link rel="stylesheet" type="text/css" href="styles.css">
<decorator:head />
</head>

<body <decorator:getProperty property="body.onload" writeEntireProperty="true" />>

<decorator:body />
<p align="right">
[
<a href="#">printable version</a> ]
</p>
</body>
</html>
</body>
</html>

 

那么新建的页面都会套用main.jsp的风格。写的不太清楚,以后再做补充。

posted @ 2008-09-12 10:26  魔豆  阅读(1162)  评论(0编辑  收藏  举报