1.1.1 serviceAction Method
In the previous Filter method, we can see the following code:
This.execute.exe cuteAction (request, response, mapping ); |
|
Figure 3.2.1 jump to action in the Filter method
The ExecuteOperations class (excute is an instance) has the following code:
Public voidExecuteAction (HttpServletRequest request, HttpServletResponse response, ActionMapping mapping)ThrowsServletException { Dispatcher. serviceAction (request, response, servletContext, mapping ); } |
|
Figure 3.2.2 execution action in ExecuteOperations
You can see from the above, and finally enter the Dispatcher class. In the source code, the comments for this class are as follows. I will slightly translate them. If there are any mistakes, please try again.
The real dispatcher (temporarily translated as a forwarder) will delegate most of its tasks to this tool class. Each instance of the basic forwarder contains the instance shared by all requests.
The main function of the ServiceAction method is to load the corresponding action class in the action configuration file and execute the appropriate action method. Or directly jump to Result.
Note the following in this class:
Action execution is implemented through a reflector. The following code is available:
UtilTimerStack.Push(TimerKey ); String namespace = mapping. getNamespace (); String name = mapping. getName (); String method = mapping. getMethod (); Configuration config = configurationManager. getConfiguration (); ActionProxy proxy = config. getContainer (). getInstance (ActionProxyFactory.Class). CreateActionProxy ( Namespace, name, method, extraContext,True,False); |
|
Figure 3.2.3 Reflection and action execution in Dispatcher
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHAgYWxpZ249 "center"> figure 3.2.4 serviceAction method sequence in the dispatcher class
1.1.2 load the struts. xml configuration file
The init () method is available in this class. The notes are as follows:
/**
* Loadconfigurations, includingbothXMLandzero-configurationstrategies, andupdateoptionalsettings, includingwhethertoreloadconfigurationsandresourcefiles.
*/
Load the configuration file, including the xml file and the automatic configuration policy. modify the configuration options, including whether to reload the configuration and resource files.
Init_FileManager (); Init_DefaultProperties (); // [1] Init_TraditionalXmlConfigurations (); // [2] Init_LegacyStrutsProperties (); // [3] Init_CustomConfigurationProviders (); // [5] Init_FilterInitParameters (); // [6] Init_AliasStandardObjects (); // [7]
Container container = init_PreloadConfiguration (); Container. inject (This); Init_CheckWebLogicWorkaround (container ); |
|
Figure 3.2.5 main content of the Init method in the dispatcher class
These methods initialize some parameters. You can see through the name. The first is to initialize file management, and the second is to load the default. properties file. Init_TraditionalXmlConfigurations is the initialization xml configuration file.
Private voidInit_TraditionalXmlConfigurations (){ String configPaths = initParams. get ("config "); If(ConfigPaths =Null){ ConfigPaths =DEFAULT_CONFIGURATION_PATHS; } String [] files = configPaths. split ("\ s * [,] \ s *"); For(String file: files ){ If(File. endsWith (". xml ")){ If("Xwork. xml". equals (file) {configurationManager. addContainerProvider (createXmlConfigurationProvider (file,False)); }Else{ ConfigurationManager. addContainerProvider (createStrutsXmlConfigurationProvider (file,False, ServletContext )); } }Else{ Throw newIllegalArgumentException ("Invalid configuration file name "); } } } |
|
Figure 3.2.6 main content of the init_TraditionalXmlConfigurations method in the dispatcher class
Where
DEFAULT_CONFIGURATION_PATHS = "struts-default.xml, struts-plugin.xml, struts. xml ";