一:介绍
在tomcat的启动过程中,tomcat会读取/WEB-INF/web.xml文件中的配置信息进行一些初始化的工作,而Struts的启动工作就从这里开始.
在web.xml文件中有如下的配置信息:
即表示tomcat启动的时候会初始化org.apache.struts.action.ActionServlet类.
二: Struts的ActionServlet的初始化
首先看一下init()的源码:
1、initInternal()
-------Initialize our internal MessageResources bundle
2、initOther()
-----Initialize other global characteristics of the controller servlet
3、initServlet()
-----Initialize the servlet mapping under which our controller servlet is being accessed
关于digester类解析xml文件请参考:
http://blog.csdn.net/wl_ldy/archive/2010/10/07/5925710.aspx
4、initChain()
5、getServletContext().setAttribute(Globals.ACTION_SERVLET_KEY, this)
将ActionServlet实例以Globals.ACTION_SERVLET_KEY为key存在ServletContext对象中
6、initModuleConfigFactory()
如果web.xml里ActionServlet配置中给出了 configFactory初始化参数,将其值指定的类做为Struts的ModuleConfigFactory,该值应该是一个完全限定类 名,Struts默认ModuleConfigFactory的实现是 org.apache.struts.config.impl.DefaultModuleConfigFactory。
7、
8、this.initModulePrefixes(this.getServletContext());
将上面while循环内产生的所有前缀生成一个String数组,放到ServletContext里。
9、this.destroyConfigDigester();
将ActionServlet类的configDigester字段重置为null。
Come from:http://gemini.javaeye.com/category/8491?show_full=true