Struts配置文件

Struts框架在启动时会读入其配置文件,根据它来创建和配置各种Struts组件.Struts配置文件使得开发者可以灵活地组装和配置各个组件,提高了应用软件的可扩展性和灵活性,可以避免硬编码.Struts配置文件是基于XML的,相应的DTD文件为struts-config_1_2.dtd.

org.apache.struts.config包

在Struts1.1中加入了org.apache.struts.config包.在Struts应用启动时,会把Struts配置文件的配置信息讯入到内存中,并把它们存放在config包中相关JavaBean类的实例中.图为org.apache.struts.config包中主要类的类框图.

org.apache.struts.config包中的每一个类都和Struts配置文件中特定的配置元素对应,例如,<action>元素和ACtionMapping类对应,<forward>元素和ActionForward类对应.由于一个<action>元素可以包含多个<forward>子元素,因此,ActionMapping类和ActionForward类之间存在一对多的关联关系.
当Struts框架完成了对配置文件的验证和解析后,就把配置文件中的信息存放在这些类的实例中.这些类的实例可以充当配置信息的运行时容器,Struts组件可以方便地通过它们来获取配置信息.
org.apache.struts.config.ModuleConfig在Struts框架中扮演了十分重要的角色.如所示,它是整个org.apache.struts.config包的核心,在Struts应用运行时用来存放整个Struts应用的配置信息.如果有多个子应用,每个子应用都会有一个ModuleConfig对象.ModuleConfig和Struts配置文件的根元素<struts-config>对应.<struts-config>根元素中包含<form-bean>,<action>和<forward>等一系列子元素,因此MouduleConfig中包含了和每个子元素对应的配置类实例.在ModuleConfig的实现类ModuleConfigimpl中定义了如下成员变量:
/**
*The set of action configurations for this module,if any,
*keyed by the<code>path</code>property.
*/
protected HashMap actionConfigs=null;
/**
*The set of JDBC data source configurations for this
*module,if any,keyed by the<code>key</code>property.
*/
protected HashMap data.Sources=null;
/**
*the set of exception handling configurations for this
*module,if any,keyed by the <code>type</code>property.
*/
protected HashMap exceptions=null;
/**
*The set of form bean configurations for this module,if any,
*keyed by the <code>name</code>property.
*/
protected HashMap formBeans=null;
/**
*The set of global forward configurations for this module,if any,
*keyed by the <code>name</code>property.
*/
protected HashMap forward=null;
/**
*The set of message resources configurations for this
*module,if any,keyed by the <code>key</code>property.
*/
protected HashMap messageResources=null;
/**
*The set of configured plug-in Actions for this module,
*if any,in the order they were declared and configured.
*/
protected ArrayList plugIns=null;
/**
*The controller configuration object for this module.
*/
protected ControllerConfig controllerConfig=null;

图中的org.apache.struts.config.ConfigRuleSet类的功能不同于其他类,它包含了解析Struts配置文件所需要的一组规则.在应用启动时,该类负责构造org.apache.struts.config包中其他用于保存配置信息的JavaBean类的实例.
 贴子相关图片:
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值