欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

SiteMesh框架的使用

系統 1750 0

首先了解什么是 SiteMesh

????? 百度百科給出的定義如下: OS(OpenSymphony)的SiteMesh是一個用來在JSP中實現頁面布局和裝飾(layout and decoration)的框架組件,能夠幫助網站開發人員較容易實現頁面中動態內容和靜態裝飾外觀的分離

????? OS(OpenSymphony )官網給出的定義是:

????? SiteMesh is a web-page layout and decoration framework and web- application integration framework to aid in creating large sites consisting of many pages for which a consistent look/feel, navigation and layout scheme is required.

???? ?SiteMesh intercepts requests to any static or dynamically generated HTML page requested through the web-server, parses the page, obtains properties and data from the content and generates an appropriate final page with modifications to the original. This is based upon the well-known GangOfFour Decorator design pattern.

??????SiteMesh can also include entire HTML pages as a Panel within another page. This is similar to a Server-Side Include, except that the HTML document will be modified to create a visual window (using the document's Meta-data as an aid) within a page. Using this feature, Portal type web sites can be built very quickly and effectively. This is based upon the well-known GangOfFour Composite design pattern.

??????SiteMesh is built using Java 2 with Servlet, JSP and XML technologies. This makes it ideal for use with J2EE applications, however it can be integrated with server-side web architectures that are not Java based such as CGI (Perl/Python/C/C++/etc), PHP, Cold Fusion, etc...

??????SiteMesh is very extensible and is designed in a way in which it is easy to extend for custom needs.

??????上面五段英文大概講了講概念和原理。在本文后面會談到,此處不做翻譯。

???????首先給出一個 直觀的例子 (來源OS官網)。

???? 2 pages are produced from different systems (one is a JSP and the other is a pre-written CGI script). Both pages are parsed and have a decorator overlaid to produce final page of a consistent look.兩個頁面由不同系統生產(一個是JSP頁面,另外一個是CGI腳本)。兩個頁面被解析并具有的裝飾器,最后生成了一致的外觀。?

SiteMesh框架的使用

這個例子的意思很清楚,最上面的welcome.jsp和search.cgi兩個頁面通過不同的途徑生成,但是通過使用SiteMesh框架,使用了相同的裝飾器(Decorator),最后形成了一致風格的界面。

下面我們通過在J2EE項目中使用SiteMesh框架來進行介紹。

第一步,在WEB-INF/web.xml增加相關配置。 代碼如下:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
?xmlns=" http://java.sun.com/xml/ns/javaee "
?xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance "
?xsi:schemaLocation=" http://java.sun.com/xml/ns/javaee
? http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd ">

?

?

增加的是一個過濾器的配置,通過配置,我們將發往服務器的所有請求都交給該過濾器進行處理。???

第二步,將所需jar包 sitemesh-2.3.jar 拷貝到WEB-INF/lib目錄下。( 該jar文件可以在OS官網 http://www.opensymphony.com/sitemesh/ ?下載到)

第三步,創建配置文件 WEB-INF/decorators.xml ,描述各裝飾器頁面。

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

<decorators defaultdir="/decorators ">????? //defaultdir屬性指定了裝飾器頁面所在路徑
??? <decorator name="main" page="main.jsp">??????? //配置名字為main的裝飾器,頁面為main.jsp
??????? <pattern>/*</pattern>??????????????????????????? //該裝飾器默認裝飾根路徑下的所有頁面
??? </decorator>
??? </decorators>

第四步,當然要創建裝飾器頁面/decorators/main.jsp頁面, 如下:

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

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
??? <head>
??????? <title>My Site - <decorator:title default="Welcome!" /></title>
??????? <decorator:head />
??? </head>

??? <body>
??? <table border="2">
??? <tr bgcolor="red">
??? <td colspan="2"> welcome to sitemesh test website (header content )</td>
??? </tr>
??? <tr>
??? <td bordercolor="blue" >

???? leftcolumn? <br>
??? ?content
??? </td>
??? <td><decorator:body /></td>
??? </tr>
??? </table>
??????? <p>footer content</p>
??? </body>
</html>

第五步,準備工作已做好,下面進行測試。編寫被裝飾頁面/index.jsp.如下:

<html>
??? <head>
??????? <title>Hello world!</title>
??? </head>

??? <body>
??????? <h2>Hello world!</h2>
??? </body>
</html>

???? 最后,訪問index.jsp頁面,生成如下頁面:

SiteMesh框架的使用

???? 而且,所有的頁面也會如同 index.jsp 一樣,被 sitemesh filter 使用裝飾模式修改成如上圖般模樣,卻不用再使用 include 標簽。這里可以多編寫一個頁面進行測試。

??? ? 至此,SiteMesh框架的使用已介紹完畢。

???? 另外再說說 decorator 裝飾器的概念。

???? 為了建立可復用的 web 應用程序 , 一個通用的方法是建立一個分層系統,如同下面一個普通的 web 應用: ?

???????? ??? · 前端 :JSP Servlets ,或 jakarta velocity ? ?

???????? ??? · 控制層框架 Controller? (Struts/Webwork) ?

??????? ???? · 業務邏輯 Business? :主要業務邏輯 ?

???????? ??? · 持久化框架 ? hibernate/jdo ?

???? 可糟糕的是前端的頁面邏輯很難被復用,當你在每一個頁面中用數之不盡的 include 來復用公共的 header, stylesheet, scripts footer 時,一個問題出現了 - 重復的代碼,每個頁面必須用 copy 來復用頁面結構,而當你需要創意性的改變頁面結構時,災難就愛上了你。

???? ? ? sitemesh 通過 filter 截取 request response ,并給原始的頁面加入一定的裝飾 ( 可能為 header,footer...) ,然后把結果返回給客戶端,并且被裝飾的原始頁面并不知道 sitemesh 的裝飾,這也就達到了脫耦的目的。

????? ?最后進行總結:

?

?????? 總結:使用 sitemesh 最通常的途徑:

????? 1. 配置好環境, ?

????? 2. WEB-INF/decroators.xml 中描述你將建立的裝飾器。 ?

????? 3. 開發在 decroators.xml 中描述的 裝飾器 ,最好存放在 /decorators 目錄下

????? 4.Over~可以看勞動成果了。

??? <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-app>

SiteMesh框架的使用


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 日韩成人中文字幕 | xx免费视频 | 一级一级一级一级毛片 | 精品国产欧美一区二区 | 大色综合色综合资源站 | 黄色av毛片 | 久久久久久www | 嫩草影院黄 | 亚洲 欧美 日韩中文字幕一区二区 | 激情网站免费观看 | 性做久久久久久免费观看欧美 | 奇米影视亚洲精品一区 | 亚洲五月 | 天天影视综合网色综合国产 | 一级做a免费视频 | 懂色一区二区三区免费观看 | 欧美系列第一页 | 天天爆操| 国产在线一区二区 | 偷拍自拍五月天 | 日本精品a在线观看 | 亚洲综合精品成人 | 欧美欧美欧美欧美 | 中文久久 | 夜夜摸天天操 | 波多久久亚洲精品AV无码 | vidz 98hd| 国产一级毛片午夜福 | 国产亚洲蜜芽精品久久 | 日本捏胸摸下面免费视频 | 婷婷色综合网 | 91久久久久久久久 | 久久久久免费视频 | 久久国产精品视频一区 | 日韩视频一区二区三区 | 久热免费在线视频 | 国产香港一级毛片在线看 | 丁香婷婷久久久综合精品国产 | 91精品国产91久久久 | 色哦色哦哦色天天综合 | 久草福利在线视频 |