|
Struts follow the Model-View-Controller pattern. ActionServlet provides the "controller" in the MVC design pattern for web applications that is commonly known as "Model 2". The standard version of ActionServlet is configured based on the following servlet initialization parameters,
- config - Comma-separated list of context-relative path(s) to the XML resource(s) containing the configuration information for the default module. (Multiple files support since Struts 1.1) [/WEB-INF/struts-config.xml].
- config/${module} - Comma-separated list of Context-relative path(s) to the XML resource(s) containing the configuration information for the module that will use the specified prefix (/${module}). This can be repeated as many times as required for multiple modules.
- configFactory - The Java class name of the ModuleConfigFactory used to create the implementation of the ModuleConfig interface.
- convertNull - Force simulation of the Struts 1.0 behavior when populating forms. If set to true, the numeric Java wrapper class types (like java.lang.Integer ) will default to null (rather than 0). (Since Struts 1.1) [false]
- rulesets - Comma-delimited list of fully qualified classnames of additional org.apache.commons.digester.RuleSet instances that should be added to the Digester that will be processing struts-config.xml files. By default, only the RuleSet for the standard configuration elements is loaded.
- validating - Should we use a validating XML parser to process the configuration file (strongly recommended)? [true]
- chainConfig - Comma-separated list of either context-relative or classloader path(s) to load commons-chain catalog definitions from. If none specified, the default Struts catalog that is provided with Struts will be used.
The main power of struts is that you can customize the controller behaviour if needed by your application. The below example will demonstrate to override the default functionality of the controller and do some application specific processing before and after the request has been processed.
(1) Struts-config.xml file
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd"> <struts-config> <!-- ================================================ Form Bean Definitions --> <form-beans> <form-bean name="inputForm" type="com.visualbuilder.InputForm" />
</form-beans> <!-- ========================================= Global Exception Definitions --> <global-exceptions></global-exceptions> <!-- =========================================== Global Forward Definitions --> <global-forwards></global-forwards> <!-- =========================================== Action Mapping Definitions --> <action-mappings> <action path="/submit" type="com.visualbuilder.SubmitAction" name="inputForm" scope="request" validate="false" input="/index.jsp"/> </action-mappings> <!-- ======================================== Message Resources Definitions --> <message-resources parameter="MessageResources" /> |