2014年6月20日 星期五

Java - Sitemesh 3

由於更換到 JEE 7, 原本的 sitemesh 2.4 也不知道為啥就不 work 了,

你罷工, 那就順便退休吧.


使用 SiteMesh3 最低需求:
  • JDK 1.5
  • A Servlet 2.5 compliant container
  • The SiteMesh runtime library

使用步驟
  1. 到 Sitemesh3 下載 library,放到 專案的 lib 下
  2. 建立最基本範例
  • web.xml 內容新增:
        <filter>
        <filter-name>sitemesh</filter-name>
        <filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class>
  </filter>

  <filter-mapping>
        <filter-name>sitemesh</filter-name>
        <url-pattern>*</url-pattern>
  </filter-mapping>
  • 新增 sitemesh3.xml 在 {Project}\WebContent\WEB-INF 下
    • Path 起啟路徑為 {Project}\WebContent\,都是路徑 與 sitemesh2  完全不同...
    • decorator 是裝飾目標的位置
<pre class="prettyprint">

<?xml version="1.0" encoding="UTF-8"?>

<sitemesh>

        <!-- 這句代表,不需要被裝飾的 Page -->

<mapping path="/WEB-INF/jsp/admin/login.jsp*" exclue="true"/>

        <!-- 這句代表,只要符合這路徑的 Page ,都會被 Sitemesh 裝飾 -->

<mapping path="/WEB-INF/jsp/admin/*" decorator="/decorators/basic.jsp" />

</sitemesh>

</pre>

  • 依 sitemesh3.xml 裡所設定的 decorator 路徑,新增其內容
    • 新增 decorators 資料夾在 WebContent
    • 新增 basic.jsp 在 {Project}\WebContent\decorators
    • sitemesh3 沒有 taglib,取而代之為
      • <sitemesh:write property="title" />
      • <sitemesh:write property="head"/>
      • <sitemesh:write property="body" />

<html>
  <head>
    <title>SiteMesh example: <sitemesh:write property='title'/></title>
    <sitemesh:write property='head'/>
  </head>
  <body>

    <h1 class='title'>SiteMesh example site: <sitemesh:write property='title'/></h1>


    <div class='mainBody'>

      <sitemesh:write property='body'/>
    </div>

    <div class='disclaimer'>Site disclaimer. This is an example.</div>

  </body>
</html>

參考:Sitemesh3

沒有留言:

張貼留言