读书人

SiteMesh 使用

发布时间: 2012-08-19 21:09:48 作者: rapoo

SiteMesh 应用

?

4.简单例子?

环境说明:

Windows2k+、Tomcat4.0+

将sitemesh-2.1.jar复制到lib目录下;修改web.xml文件,也就是在web.xml中加入粗倾体标记的部分;

<?xml version="1.0" encoding="GB2312"?>

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

<filter>

</filter>

<filter-mapping>

??????????????</filter-mapping>

</web-app>

?

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

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

<html>

<head>

<meta http-equiv="Content-Language" content="zh-cn">

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<meta name="GENERATOR" content="Microsoft FrontPage 4.0">

<meta name="ProgId" content="FrontPage.Editor.Document">

<title>AP -</title>

<decorator:head />

</head>

<body>

<table border="0" cellpadding="2" width="100%" height="151">

????

?????

???

??<td width="20%" height="28" bgcolor="#F3F3F3" valign="top" >

<page:applyDecorator page="/menu.jsp" name="panel" />

</td>

???<decorator:body /></td>

?????

??????</table>

</body>

</html>

?

说明:

<decorator:title default="Welcome to test sitemesh!" />:读取被装饰页面的标题,并给出了默认标题。

<decorator:head />:读取被装饰页面的<head>中的内容;

<page:applyDecorator page="/menu.jsp" name="panel" />:把menu.jsp文件用panel指定的装饰器装饰,并把结果插入到该位置;

<decorator:body />:读取被装饰页面的<body>中的内容;

当然还有很多的标签,这里不再详细描述。

<?xml version="1.0" encoding="ISO-8859-1"?>

<decorators defaultdir="/decorators">

???

???????</decorator>

?

???

???

</decorators>

这里我是把对所有的请求都用mymail.jsp来装饰。

好了,run一下你的“小板凳”!你会看到如下结果:

SiteMesh 使用?

5.总结
??? 使用sitemesh给我们带来的是不仅仅是页面结构问题,它的出现让我们有更多的时间去关注底层业务逻辑,而不是整个页面的风格和结构。它让我们摆脱了大量用include方式复用页面尴尬局面,它也提供了很大的灵活性以及给我们提供了整合异构Web系统页面的一种方案。我们期望它在未来的版本中会有更多的特性出现。
引自:http://blog.csdn.net/gagaghost/article/details/71053

?