一、使用Webx框架建立的项目目录里结构及重要文件
1. java文件的存放位置
2. vm文件的存放位置
3. uri.xml.vm文件的位置
在uri.xml.vm文件中,有如下配置,对应了Servlet path :/user的url映射
<content-uri name="appServer" expose="true">
<serverURI>http://${consign_appServer_host}serverURI>
content-uri>
<turbine-uri name="userModule" expose="true" extends="appServer">
<contextPath>/contextPath>
<componentPath>usercomponentPath>
turbine-uri>
4. webx bean工厂配置文件的存放位置
二、Webx里面有三个比较重要的概念,action,screen,control
1、screen就相当于select查询,比如请求一个链接http://localhost:8080/test/get_user.vm,就会有GetUserScreen中的execute方法来获得用户信息,然后将其渲染到get_user.vm显示到页面。
示例代码:
2、action就相当于insert或update,比如注册页面,需要填写表单信息,然后点击注册按钮,请求http://localhost:8080/test/register.do,就会有UserAction中的doRegister方法来处理这些数据,插入到数据库表中。
示例代码:
三、webx执行的流程
当在浏览器里敲入http://wuliu.daily.taobao.net:80/user/my_test.htm时,在webx中发生了哪些事呢?
分析url
-
URL scheme:http:
-
Server name:wuliu.daily.taobao.net
-
Server port:80
-
Context path:/user
-
Servlet path:/my_test.htm
-
Target: /myTest.vm
-
user称为context path,服务器把这个请求交给user应用来接管
-
my_test.htm称为servlet path,在web.xml中把*.htm映射到webx controller servlet,webx controller servlet就接管了这个请求
-
webx controller servlet激活pipeline, 继而调用AnalyzeURLValue来分析 /my_test.htm是什么意思.根据默认规则,/my_test.htm被转换成/myTest.vm
-
根据traget查找screen模板:/screen/user/myTest.vm模板
-
根据target查找screen模块的类:
com.taobao.consign.web.module.screen.user.MyTest.java(找到该类)
com.taobao.consign.web.module.screen.user.Default.java
com.alibaba.turbine.module.screen.TemplateScreen(默认screen类)如果还有layout布局,则执行第6、7步
-
执行screen类,并渲染screen模板
-
根据target查找layout模板,渲染layout模板
8. 渲染在layout模板中引用的control