一個namespace下能夠聲明多個element。java
擴展點:將namespace和接口關聯起來。
捐獻:將element和實現關聯起來。git
mvn archetype:generate -DgroupId=com.alibaba.webx -DartifactId=tutorial1 -Dversion=1.0-SNAPSHOT -Dpackage=com.alibaba.webx.tutorial1 -DarchetypeArtifactId=archetype-webx-quickstart -DarchetypeGroupId=com.alibaba.citrus.sample -DarchetypeVersion=1.8 -DinteractiveMode=false
該示例是tutorial1示例中的「5. Form Validation」部分的內容。github
mvn archetype:generate -DgroupId=com.alibaba.webx -DartifactId=login-webx3-tutorial -Dversion=1.0-SNAPSHOT -Dpackage=com.alibaba.webx.tutorial -DarchetypeArtifactId=archetype-webx-quickstart -DarchetypeGroupId=com.alibaba.citrus.sample -DinteractiveMode=false
git clone https://github.com/webx/citrus-sample.git cd citrus-sample/petstore mvn clean install cd web mvn jetty:run-war
web應用根目錄
就是指的是web項目的根目錄。
/WEB-INF/web.xml
上述的/不是相對於操做系統而言,而是針對web項目而言。web
每一端都有input chaset 和output charset。這就比如socket通訊,每一端都有輸入流和輸出流。spring
AnalyzeURLValve:取得target,action,actionEvent。
(1)經過request.getServletPath()+request.getPathInfo()獲取請求的pathInfo,並經過MappingRuleService將pathInfo轉爲target。
(2)取得請求中的action參數。經過MappingRuleService獲得最後的action。
(3)獲得請求中的actionEvent。ruby
對開發者的要求:
(1)配置MappingRuleService的映射規則。即<services:mapping-rules>bash
PerformActionValve:根據action參數找到具體的action類,而後執行其execute()方法。
ModuleLoaderService.getModule(action).execute()
Module就是一個含execute()方法的接口。架構
<direct-module-rule>元素表示直接映射module,這是最簡單的模塊映射規則。
它映射Module的原理是:將URL路徑"/"替換成".",除去文件名後綴,將最後一個單詞首字母改爲大寫,以符合模塊命名的規則。
好比http://abc.com/helloapp/path/hello.htm
webx根據你訪問的URL target 「path/hello.htm」,定位到 Module 「path.hello.class」
<services:module-loader>
<ml-factories:class-modules> <search-packages type="$1" packages="com.alibaba.sample.petstore.web.common.module.*" /> </ml-factories:class-modules> </services:module-loader>
petstore-web的src目錄以下:
src
└─main
├─java
│ └─com
│ └─alibaba
│ └─sample
│ └─petstore
│ └─web
│ ├─common
│ │ └─util
│ ├─home
│ │ └─module │ │ └─screen │ ├─servlet │ ├─store │ │ └─module │ │ ├─action │ │ ├─control │ │ └─screen │ └─user │ └─module │ ├─action │ └─screen └─webapp ├─common │ └─templates │ ├─layout │ └─screen ├─home │ ├─css │ ├─images │ └─templates │ ├─control │ ├─layout │ └─screen ├─META-INF │ └─autoconf ├─store │ ├─css │ ├─images │ └─templates │ ├─control │ ├─layout │ └─screen │ └─edit ├─user │ ├─css │ └─templates │ ├─control │ ├─layout │ └─screen └─WEB-INF ├─common │ └─$petstore_upload ├─home ├─store └─user
main下的兩個目錄分別是java和webapp。
從代碼結構來看,整個petstore-web分紅了3個模塊(子應用),分別是home、user、store等3個模塊。另外還有一個公共模塊common。
java部分在com.alibaba.sample.petstore.web
下有四個主要的子包common、home、user、store,分別對應4個模塊。
而後在每一個子包下面纔是action、control、screen等module。
com.alibaba.sample.petstore.web.子模塊.module.action.LoginAction; com.alibaba.sample.petstore.web.子模塊.module.screen.LoginAction; com.alibaba.sample.petstore.web.子模塊.module.control.LoginAction;
webapp目錄下有4個子模塊目錄和WEB-INF目錄。
四個子模塊目錄分別是common、home、user、store。每一個裏面都是存放的該模塊的css、img、template等資源。
WEB-INF目錄下的內容:
每一個子模塊的webx-*.xml中都有一個裝載模塊的配置<services:module-loader>,對應着java中的package。
例如webx-home.xml中的配置片斷是:<search-packages type="$1" packages="com.alibaba.sample.petstore.web.home.module.*" /> 例如webx-user.xml中的配置片斷是:<search-packages type="$1" packages="com.alibaba