SiteMesh3 介紹和使用


    Sitemesh是由一個基於Web頁面布局、裝飾及與現存Web應用整合的框架。它能幫助我們再由大量頁面工程的項目中創建一致的頁面布局和外觀,如一 致的導航條、一致的banner、一致的版權等。它不僅能處理動態的內容,如JSP、PHP、ASP、CGI等產生的內容,還能處理靜態的內容,比如 HTML的內容,使得它的內容也符合你的頁面結構的要求。甚至它能像include那樣將HTML文件作為一個面板的形式嵌入到別的文件中去。通常我們都是用include標簽在每個jsp頁面中來不斷的包含各種header, stylesheet, scripts and footer,現在,在sitemesh的幫助下,我們可以開心的刪掉他

QQ截圖20140801173033

要添加的文件:sitemesh-3.0-alpha-2.jar,struts-sitemesh-plugin-2.3.16.3.jar,sitemesh3.xml,最后要在web.xml文件中配置一下sitemesh,配置如下 :

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>SiteMesh3TestProject</display-name>
  <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>
</web-app>

然后,就是新建你的母版頁了(Template.jsp),如下:

<!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> <sitemesh:write property='title'/></title>
     <sitemesh:write property='head'/>
  </head>
  <body>
      <sitemesh:write property='body'/>
  </body>
</html>

接着,再修改sitemesh.xml文件,這里我修改的是我自己的母版頁,個人對應自己的地址:

<sitemesh>
  <mapping path="/*" decorator="/Template.jsp"/>
</sitemesh>

這樣就完成了對sitemesh3母版頁的設置,之后你就可以新建jsp頁面來引用這個模板頁,用最少的代碼干更多的事,呵呵是不是很方便啊,大家一起來試試看吧,有什么問題可以發送我的常用郵箱:zhangwei900808@126.com,或者qq:1576410833。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM