sitemesh 簡單入門
2008年4月16日 edited by dingdangxiaoma
引用:sitemesh應用Decorator模式,用filter截取request和response,把頁面組件head,content,banner結合為一個完整的視圖。
sitemesh 是OpenSymphony 組織下的子項目。
準備:從官方下載 sitemesh包拷貝到你項目下的lib下。
web.xml 添加以下內容。
會看到:
這就是一個簡單的例子,只是說明了整個問題的應用,而沒有涉及到各個細節問題。
當然,sitemesh 還有很多內容。支持的視圖不公包含了.jsp還有velocity freemarker等。
參考資料:
http://www.java3z.com/cwbwebhome/article/article2/2962.html?id=1668
http://www.cjsdn.net/post/view?bid=29&id=178862
引用:sitemesh應用Decorator模式,用filter截取request和response,把頁面組件head,content,banner結合為一個完整的視圖。
sitemesh 是OpenSymphony 組織下的子項目。
準備:從官方下載 sitemesh包拷貝到你項目下的lib下。
web.xml 添加以下內容。
<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>
WEB-INF 下建立decorators.xml<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>
<?xml version="1.0" encoding="UTF-8"?>
<decorators defaultdir="/decorators">
<decorator name="main" page="main.jsp"> <!--裝飾頁面-->
<pattern>*</pattern> <!-- 裝飾映射-->
</decorator>
</decorators>
在webroot 下新建:decorators/main.jsp<decorators defaultdir="/decorators">
<decorator name="main" page="main.jsp"> <!--裝飾頁面-->
<pattern>*</pattern> <!-- 裝飾映射-->
</decorator>
</decorators>
<%@ page contentType="text/html; charset=GBK"%>
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator"
prefix="decorator"%>
<html>
<head>
<title>
<decorator:title default="decorators
" />
</title>
<decorator:head />
</head>
<body>
sitemesh的例子
<hr>
<decorator:body />
<hr>
DingDangXiaoMa@163.com
</body>
</html>
建立 index.jsp<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator"
prefix="decorator"%>
<html>
<head>
<title>
<decorator:title default="decorators

</title>
<decorator:head />
</head>
<body>
sitemesh的例子
<hr>
<decorator:body />
<hr>
DingDangXiaoMa@163.com
</body>
</html>
<%@ page contentType="text/html; charset=GBK"%>
<html>
<head>
<title>343</title>
</head>
<body>
<p>本頁只有一句,就是本句.</p>
</body>
</html>
當通過訪問服務器時:http://localhost/sitemesh/index.jsp時。<html>
<head>
<title>343</title>
</head>
<body>
<p>本頁只有一句,就是本句.</p>
</body>
</html>
會看到:
sitemesh的例子
本頁只有一句,就是本句.
DingDangXiaoMa@163.com
這就輸出結果了。訪問的結果自動裝載上了main.jsp樣式。這就是添加了sitemesh 過濾的結果。本頁只有一句,就是本句.
DingDangXiaoMa@163.com
這就是一個簡單的例子,只是說明了整個問題的應用,而沒有涉及到各個細節問題。
當然,sitemesh 還有很多內容。支持的視圖不公包含了.jsp還有velocity freemarker等。
參考資料:
http://www.java3z.com/cwbwebhome/article/article2/2962.html?id=1668
http://www.cjsdn.net/post/view?bid=29&id=178862
posted on 2008-04-16 11:13 叮當小馬 閱讀(285) 評論(0) 編輯 收藏 所屬分類: OpenSymphony