一个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