views:

152

answers:

3
  1. what does it means "struts controller reads the struts-config.xml file" when ever web application is started?

  2. is controller create action objects while reading the struts-config file?

A: 

1. what does it means "struts controller reads the struts-config.xml file" when ever web application is started?

The "read" means that Struts will parse the XML file and create object representations of the tags you have declared inside (e.g. the ActionMapping reflects an <action> tag). These objects will then be used whenever Struts needs to know different configuration information avoiding the need to do costly I/O operations to go to the XML file each time.

The class that contains the rules for parsing the file is org.apache.struts.config.ConfigRuleSet (javadoc: The set of Digester rules required to parse a Struts configuration file (struts-config.xml)).

2. is controller create action objects while reading the struts-config file?

No, this is done later, when a request comes in.

When a request comes in, Struts tries to find an already existing Action instance that matches the URL path. If it finds it, it returns it, else it will create it and store it for later use before returning it.

The RequestProcessor.processActionCreate method does this (javadoc: return an Action instance that will be used to process the current request, creating a new one if necessary).

dpb
+1  A: 

is controller create action objects while reading the struts-config file

I think it does that lazily (when the URL is accessed). At least Struts1 does.

Thilo
+1  A: 

when struts reads in the file it is only parsing it and loading the action definitions. The only errors you will get are XML parsing errors. Not sure about Struts 2, but in struts 1 it will not validate that the objects or the forwarded targets exist or compile. That is a runtime check

james