sitemesh应用
生活随笔
收集整理的這篇文章主要介紹了
sitemesh应用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
參考:
http://www.iteye.com/topic/251521
http://www.jb51.net/web/70208.html
依賴:
<!-- https://mvnrepository.com/artifact/opensymphony/sitemesh --><dependency><groupId>opensymphony</groupId><artifactId>sitemesh</artifactId><version>2.4</version></dependency>使用說明:
STEP1:配置web.xml
<filter><filter-name>sitemesh</filter-name><filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class> </filter> <filter-mapping><filter-name>sitemesh</filter-name><url-pattern>/*</url-pattern> </filter-mapping>STEP2:在[web-app]/WEB-INF/新建一個decorators.xml文件
<?xml version="1.0" encoding="utf-8"?> <decorators defaultdir="/decorators"> <!-- 此處用來定義不需要過濾的頁面 --> <excludes> </excludes> <!-- 用來定義裝飾器要過濾的頁面 --> <decorator name="main" page="main.jsp"> <pattern>/*</pattern> </decorator> </decorators>STEP3:在[web-app]下創建一個decorators文件夾,在該文件下再創建一個裝飾頁面main.jsp,包含以下內容:
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <!-- 第一個裝飾頁面 --> <head> <!-- 從被裝飾頁面獲取title標簽內容,并設置默認值--> <title><decorator:title default="默認title"/></title> <!-- 從被裝飾頁面獲取head標簽內容 --> <decorator:head/> </head> <body> <h2>SiteMesh裝飾header</h2> <hr /> <!-- 從被裝飾頁面獲取body標簽內容 --> <decorator:body /> <hr /> <h2>SiteMesh裝飾footer</h2> </body> </html>STEP4:在[web-app]下創建被裝飾頁面index.jsp,包含以下內容:
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!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>被裝飾(目標)頁面title</title> </head> <body> <h4>被裝飾(目標)頁面body標簽內內容。</h4> <h3>使用SiteMesh的好處?</h3> <ul> <li>被裝飾(目標)頁面和裝飾頁面完全分離。</li> <li>做到真正的頁面復用,一個裝飾頁面裝飾多個被裝飾(目標)頁面。</li> <li>更容易實現統一的網站風格。</li> <li>還有。。。</li> </ul> </body> </html>通過SiteMesh裝飾,不需要在每個目標頁面中將header和footer等共同文件include進去,被裝飾(目標)頁面和裝飾頁面完全分離。
總結
以上是生活随笔為你收集整理的sitemesh应用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 教你炒股票19:学习缠中说禅技术分析理论
- 下一篇: 操作系统中常见的进程调度算法