④ 调用
initChain();
读取web.xml
中命令链文件初始值chainConfig
protected String chainConfig = "org/apache/struts/chain/chain-config.xml"
;
//
④
initChain();
//
如没有chainConfig
参数,则使用默认
"org/apache/struts/chain/chain-config.xml"
String value;
value = getServletConfig().getInitParameter("chainConfig");
if (value != null) {
chainConfig = value;
}
ConfigParser parser = new ConfigParser();
List urls = splitAndResolvePaths(chainConfig);
URL resource;
// chainConfig
替换了原来传统的在
RequestProcessor
类中执行的
HTTP
请求处理
for (Iterator i = urls.iterator(); i.hasNext();) {
resource = (URL) i.next();
log.info("Loading chain catalog from " + resource);
parser.parse(resource);
}
/************************************************************
// org.apache.struts.action.
RequestProcessor
.java
的process
方法中,一些方法如
processLocale
(request, response);
processContent
(request, response);
processNoCache
(request, response);
.......
被
"org/apache/struts/chain/chain-config.xml"
中下列配置所取代
<command
className="org.apache.struts.chain.commands.servlet.SelectLocale"/>
<command
className="org.apache.struts.chain.commands.servlet.SetContentType"/>
<command
className="org.apache.struts.chain.commands.servlet.RequestNoCache"/>
.......
好处是充分降低了代码内部方法与方法之间的耦合度
************************************************************/
在④
/
⑤
之间
//
把servlet
对象存储到servletContext
中,属性名为Globals.ACTION_SERVLET_KEY
(
"
org.apache.struts.action.ACTION_SERVLET
"
)
getServletContext().setAttribute(Globals.ACTION_SERVLET_KEY, this);
⑤ 调用
initModuleConfigFactory();
和
initModuleConfig("", config);
创建
ModuleConfig
对象。Struts
中的MessageResource
、PlugIn
、数据源等,都是通过ModuleConfig
来实现的。
//
初始化ModuleConfig
配置工厂
initModuleConfigFactory();
//
⑴
//
由配置工厂实例化一个ModuleConfig
的对象
ModuleConfig moduleConfig = initModuleConfig
("", config); //
⑵
⑴
initModuleConfigFactory();
所做的工作:
//
得到web.xml
中"configFactory"
参数,如果找不到,则使用
默认工厂
String configFactory = getServletConfig().getInitParameter("configFactory
");
if (configFactory != null) {
ModuleConfigFactory.setFactoryClass
(configFactory);
}
<servlet>
<servlet-name
>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>configFactory
</param-name>
<!--
得到"configFactory"
参数-->
<param-value>com.lively.base.webapp.UserModuleConfigFactory</param-value>
</init-param>
.......
</servlet>
在ModuleConfigFactory.java
中的setFactoryClass
方法,
public static void setFactoryClass(String factoryClass) {
ModuleConfigFactory.factoryClass = factoryClass;
ModuleConfigFactory.clazz = null;
}
其中
protected static Class clazz = null;
protected static
String factoryClass =
"org.apache.struts.config.impl.DefaultModuleConfigFactory
"
;
⑵
initModuleConfig
("", config);
所做的工作:
// Parse the configuration for this module
ModuleConfigFactory factoryObject = ModuleConfigFactory.createFactory
(); //
Ⅰ
ModuleConfig config = factoryObject.createModuleConfig
(prefix); //
Ⅱ
Ⅰ
ModuleConfigFactory.createFactory
();
方法中:
protected static Class clazz = null;
protected static
String factoryClass =
"org.apache.struts.config.impl.DefaultModuleConfigFactory
"
;
if (clazz == null) {
clazz = RequestUtils.applicationClass
(factoryClass);
}
factory = (ModuleConfigFactory) clazz.newInstance();
而RequestUtils.applicationClass
通过classLoader
加载一个
org.apache.struts.config.impl.DefaultModuleConfigFactory
Ⅱ
ModuleConfig config = factoryObject.createModuleConfig
(prefix);
方法中:
//
通过new ModuleConfigImpl(prefix);
设置一些变量的初始值,在
initModuleConfig
("", config);
方法的最后会
把ModuleConfig
对象放置到servletContext
中 (参见
Ⅴ
)
protected String prefix = null;
protected HashMap actionConfigs = null;
protected List actionConfigList = null;
protected String actionFormBeanClass = "org.apache.struts.action.ActionFormBean";
protected String actionMappingClass = "org.apache.struts.action.ActionMapping";
protected String actionForwardClass = "org.apache.struts.action.ActionForward";
protected boolean configured = false;
protected ControllerConfig controllerConfig = null;
protected HashMap exceptions = null;
protected HashMap formBeans = null;
protected HashMap forwards = null;
protected HashMap messageResources = null;
protected ArrayList plugIns = null;
public ModuleConfigImpl(String prefix) {
super();
this.prefix = prefix;
this.actionConfigs = new HashMap();
this.actionConfigList = new ArrayList();
this.actionFormBeanClass = "org.apache.struts.action.ActionFormBean";
this.actionMappingClass = "org.apache.struts.action.ActionMapping";
this.actionForwardClass = "org.apache.struts.action.ActionForward";
this.configured = false;
this.controllerConfig = null;
this.exceptions = new HashMap();
this.formBeans = new HashMap();
this.forwards = new HashMap();
this.messageResources = new HashMap();
this.plugIns = new ArrayList();
}
Ⅲ
protected String config = "/WEB-INF/struts-config.xml"; //
②
initOther();
⑤
initModuleConfig ();
protected Digester configDigester = null; //
⑤
initModuleConfig ();
//
初始化Digester
,
Digester digester = initConfigDigester();
initConfigDigester();
所做的工作:
// Create a new Digester instance with standard capabilities
configDigester = new Digester();
configDigester.setNamespaceAware(true);
configDigester.setValidating(this.isValidating());
configDigester.setUseContextClassLoader(true);
//
解析struts
配置文件之前,首先添加默认的解析规则
configDigester.addRuleSet(new ConfigRuleSet());
for (int i = 0; i < registrations.length; i += 2) {
URL url = this.getClass().getResource(registrations[i + 1]);
if (url != null) {
configDigester.register(registrations[i], url.toString());
}
}
//
通过getServletConfig().getInitParameter("rulesets");
从web.xml
中读取用户自定义的解析规则(用","
分开的org.apache.commons.digester.RuleSet
列表)
this.addRuleSets();
分享到:
相关推荐
可以对struts进行深入的学习.个人觉得是个很不错的文档,因积分的问题不得不出卖自己的珍藏之物
struts1学习资料:里面包含struts源码工程 ActionServlet DispatchAction Action LookUpDispatchAction的用法 还包含html logic bean tiles标签的详细使用方法和validate验证框架的具体案例
如下图2所示: <br/> 控制:通过图2大家可以看到有一个XML文件Struts-config.xml,与之相关联的是Controller,在Struts中,承担MVC中Controller角色的是一个Servlet,叫ActionServlet。ActionServlet是一...
The file struts-config.xml instructs ActionServlet on how to use the extended classes. There are several advantages to this approach: • The entire logical flow of the application is in a ...
网上书店(使用技术为JSP+Servlet+IBatis,完成前台功能) 网上银行(使用技术为Struts+Hibernate。 JSP页面采用Tiles框架布局,表单验证没有采用Validator框架验证。 JDK:1.4以上 数据库:SQL Server2000 开发工具...
第1篇为技能学习篇,主要包括Java Web开发环境、JSP语法、JSP内置对象、Java Bean技术、Servlet技术、EL与JSTL标签库、数据库应用开发、初识Struts2基础、揭密Struts2高级技术、Hib锄劬e技术入门、Hibernate高级应用...
行动和ActionServlet的控制器实现 ,视图层的JSP文件组成。中央控制器控制,接收到一个请求,这个请求重定向到相应的 模块控制器执行动作。随后,该模块控制器处理请求并返回结果到中央控制器使用一个 JavaBean对象...
以及最早学习到的java web中的javax.servlet.Filter的概念, 都是一种链式的处理流程,这一个环节处理完成,然后处理另一个环节,这样就可以在一个处理本身的之前和之后做一些事情了。 比如说,struts2中Action在...
非常适合java学习的一个项目,我们的刘春阳老师创造性的把所有的java相关的技术都结合在这一个Training项目中,深入浅出的传授给我们的知识,倾心大奉献了:里面包含了jsp,servlet,struts,spring,hibernate,Ext,js,css,...
JSP(TagLib)——>ActionForm——>Action ——> Event——>EJBAction——>EJB ——>DAO——>Database JSP(TagLib) (forward) <——Action <——EventResponse<—— ??Turbine:??主要应用方面:WEB层。??主要应用...
该案例既提供了ide无关的、基于ant管理的项目源码,也提供了基于netbeans ide的项目源码,最大限度地满足读者的需求。 作者简介: 李刚,从事10年的Java EE应用开发。曾任LITEON公司的J2EE技术主管,负责该公司的...