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 ()); }
}