Struts1源码查看(1)

struts1在tomcat启动的时候初始化:

由tomcat调用init()方法.实际上调用的是struts1中的init()方法.

在struts1中的init方法解析:

public void init()  throws ServletException {
        try
        {
            initInternal();  
 initOther();
            initServlet();
            getServletContext().setAttribute("org.apache.struts.action.ACTION_SERVLET", this);
            initModuleConfigFactory();
            ModuleConfig moduleConfig = initModuleConfig("", config);
            initModuleMessageResources(moduleConfig);
            initModuleDataSources(moduleConfig);
            initModulePlugIns(moduleConfig);
            moduleConfig.freeze();
            for(Enumeration names = getServletConfig().getInitParameterNames(); names.hasMoreElements();)
            {
                String name = (String)names.nextElement();
                if(name.startsWith("config/"))
                {
                    String prefix = name.substring(6);
                    moduleConfig = initModuleConfig(prefix, getServletConfig().getInitParameter(name));
                    initModuleMessageResources(moduleConfig);
                    initModuleDataSources(moduleConfig);
                    initModulePlugIns(moduleConfig);
                    moduleConfig.freeze();
                }
            }

            initModulePrefixes(getServletContext());
            destroyConfigDigester();
        }
        catch(UnavailableException ex)
        {
            throw ex;
        }
        catch(Throwable t)
        {
            log.error("Unable to initialize Struts ActionServlet due to an unexpected exception or error thrown, so marking the servlet as unavailable.  Most likely, this is due to an incorrect or missing library dependency.", t);
            throw new UnavailableException(t.getMessage());
        }
    }



initInternal(); //利用factory创建一个消息资源类.MessageResources

initOther();

// 根据web.xml中的配置得到config, convertNull所对应的值,

根据源代码,我们可以知道,convertNull可以设置为:on yes true 1 y

// 如果配置了convertNull,就会注册所有的converter(struts默认的),用来将formBean中的String参数转换成需要的类型.

initServlet(); //这里就是根据在web.xml中配置信息,利用Digester来解析xml文件.

加载Servlet-mapping.加载 Servlet-name.加载url-pattern这三个属性.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值