Pre-loading actionservlet of layered progressive Struts1 (iv)

Source: Internet
Author: User
Tags config tomcat

The execution of struts is equivalent to two phases, preload and execution, and the preload phase is the content that starts when Tomcat starts, and at this point we do not really enter the jump logic, this blog we analyze the preload phase.

Configuration file

Remember how the Web.xml servlet about struts is configured?

 <servlet-name>action</servlet-name> <servlet-class> Org.apache.struts.action.actionservlet</servlet-class> <init-param> <param-name>config</par am-name> <param-value>/WEB-INF/struts-config.xml</param-value> </init-param> <init-p aram> <param-name>debug</param-name> <param-value>2</param-value> </init-par am> <init-param> <param-name>detail</param-name> <param-value>2</param-value > </init-param> <load-on-startup>2</load-on-startup> </servlet> <!--Standard Ac tion Servlet Mapping--> <servlet-mapping> <servlet-name>action</servlet-name> <url-patter N>*.do</url-pattern> </servlet-mapping> 

Where the <load-on-startup>2</load-on-startup> refers to when Tomcat is started, the actual as long as the number is greater than 0, meaning that tomcat boot is executed, in order to enter the debugging, we change this here to 0.

<load-on-startup>0</load-on-startup>

Main function init ()

After debugging, when this function is executed, the preload phase of struts is over, so we'll look at this function primarily.

/** * <p>initialize this servlet. 
 Most of the processing has been factored into * support methods so this can override particular functionality at a * Fairly granular level.</p> * * @exception servletexception If we cannot configure ourselves correctly/PU   
    Blic void Init () throws Servletexception {//wraps the entire initialization in a try/catch to better handle Unexpected exceptions and errors to provide better \/to the feedback try {init  
        Internal ();  
        Initother ();  
      
        Initservlet ();  
        Getservletcontext (). setattribute (Globals.action_servlet_key, this);  
        Initmoduleconfigfactory ();  
        Initialize modules as needed moduleconfig moduleconfig = Initmoduleconfig ("", config);  
        Initmodulemessageresources (moduleconfig);  
        Initmoduledatasources (moduleconfig);  
        Initmoduleplugins (moduleconfig);  Moduleconfig.freeze ();
      
        Enumeration names = Getservletconfig (). Getinitparameternames ();  
            while (Names.hasmoreelements ()) {String name = (String) names.nextelement ();  
            if (!name.startswith ("config/")) {continue;  
            String prefix = name.substring (6);  
            Moduleconfig = initmoduleconfig (prefix, Getservletconfig (). Getinitparameter (name));  
            Initmodulemessageresources (moduleconfig);  
            Initmoduledatasources (moduleconfig);  
            Initmoduleplugins (moduleconfig);  
        Moduleconfig.freeze ();  
      
        } this.initmoduleprefixes (This.getservletcontext ());  
    This.destroyconfigdigester ();  
    catch (Unavailableexception ex) {throw ex; The catch (Throwable t) {//The follow error message isn't retrieved from internal message/R Esources as they may don't have been able to have beeN//Initialized Log.error ("Unable to initialize Struts Actionservlet due to an" + "Unex  Pected 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 ()); }      
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.