In-depth understanding Struts-config.xml

xiaoxiao2021-03-30  198

Make a clear role in the elements in Struts-Config.xml, which has a great advantage of building a web project. is the root element of Struts, which mainly has 8 sub-elements, DTD is defined as follows:

8 elements , The following describes: 1. Date-sources element Date-Sources Element is used to configure the data source required for the application. The Java language provides a javax.sql.datesource interface, and all data sources must implement the interface. The following configuration: ................... In Action, access : Javax.sql.datasource DataSource; java.sql.connection myconnection; try {datasource = getDataSource (request); myconnection = datasource.getConnection ();} .......... If it is a multi-data source, you can use the following configuration: .................... ................. <

2. Form-beans Elements This element is primarily used to configure the class verification class. It contains the following properties: 1. ClassName: Generally, specify and specify the configuration class with the Form-bean, default is org.apache.struts.config.FormBeanconfig, if customized, the FormBeanconfig class must be extended. There is no. 2. Name: The only identification of ActionForm bean. have to. 3. TYPE: The full class name of ActionForm. have to. As shown below: If it is dynamic action FormBean, you must also configure Form -bean element of form-property child. It contains four properties, three above, and an initial element: set the initial value of the form field in the form of a string. If this property is not set, the basic type is 0, if it is an object is NULL. There is no. As shown below:

< / FORM-Beans>

3. Global-Exceptions element This element mainly configures an exception handling, its Exception child element represents a global exception configuration. Struts takes a configuration to handle exceptions. It is used to set the mapping between Java exceptions and exception handling class org.apache.struts.Action.ExceptionHandler. It has seven properties as follows: 1. ClassName: Specifies the configuration class corresponding to the Exception element, default is: org.apache.struts.config.exceptionconfig. There is no. 2. Handler: Specify an exception class, default is: org.apache.struts.Action.exceptionHandler. There may be no 3. key: Specify that the exception is described in Resource Bundle Key 4. Path: Specifies the forwarding path when an exception occurs. 5. Scope: Specify the storage range of the ActionMessages instance, optional values ​​include: Request and session, default to request. There is no. 6. TYPE: Specifies the name of the required processing exception class, must. 7. Bundle: Spessage bundle as follows: 4. Global-forwards element This element is mainly used to declare the overall forwarding relationship, which has the following four properties: 1. ClassName: and the FORWARD element corresponding to the configuration class, default is: org.apache. Struts.Action.ActionForward. There is no. 2. Contextrelative: When this is true, the path property begins with "/", which is default to false with respect to the current URL of the current context. There is no. 3. Name: The logical name of the forwarding path. Required. 4. PATH: Forward or redirect URL, when contextrelative = false, the URL path is relative to the current application (Application), indicating the URL path relative to the current context. 5. Redirect: When this item is TURE, it means a redirection operation. When this item is set to FALSE, the steering operation is indicated. The default is false. As shown below:

5. Action-mapings element describes mapping from a particular request path to the corresponding Action class. It has the following attributes: 1. Attribute: Settings and action Actionform Beans within the Request and Session range. Such as: The Form Bean is stored in the Request range, which is set to "MyBenas", and the bean can be returned to the instance of the bean in Request.GetAttribute ("MyBenas"). 2. ClassSName: The configuration element corresponding to the action element, default is: org.apache.struts.Action.ActionMapping. 3. Forward: Forwarded URL path. 4. INCLUDE: Specifies the included URL path. 5. INPUT: Enter the URL path of the form. When the table verification fails, the request will forward the request to the URL. 6. Name: Specifies the name of the Action FormBean associated with action, which must be defined in Form-bean. 7. PATH: Specifies the path to access Action, starting with "/", no extension. 8. Parameter: Specifies the configuration parameters of the ACTGION. In the Execute () method of the Action class, you can call the getParameter () method of the ActionMApping object to read the configuration parameters. 9. ROLES: Specifies the security role that allows calling this action, between multiple characters, spaced apart, when the request is processed, the RequestProcessor determines whether the user has permission to call Action. 10. Scope: Specifies the existence scope of the ActionForm Bean, optional to request and session, default to session. 11. TYPE: Specifies the full class name of the Action class. 12. Unknown: If this is true, it means that all invalid Action URLs you can send can handle the user, default is false; 13. Validate: Specifies whether you want to call an Action FormBean's Validate method, the default is TURE. Note: Forward, Include The TYPE attribute can only be selected one item. As shown below: Note: This Forward refers to a local forwarding path. Global-forwards represents a global forwarding path.

6. Controller element This element is used to configure an ActionServlet. It has the following properties. 1. Buffersize: Specifies the input buffer size, optional, default is 4096 2. ClassName: Specify the configuration class corresponding to the Controller element, default is org.apache.struts.config.controllerconfig 3. CONENTTYPE: Character encoding, if This setting is overwritten in the Action and JSP web pages. 4. Locale: Specifies whether to save the Locale object to the current user's session, the default value is false. 5. ProcessorClass: Specifies the full path to the Java class responsible for the request. 6. Tempdir: Specifies the temporary work directory for processing the file. If this item is not set, the servlet container is used as a temporary work directory assigned by the web application. 7. Nochache: If True: Adjubes specific header parameters in response results: Pragma, Cache-Control, and Expise, prevent the page from being saved in the client's browser, default is false as follows:

7. Message-Resources element mainly configures localized message text, which has the following properties. 1. ClassName: The configuration class corresponding to the Message-Resources element, default is org.apache.struts.config.MessageResourcesConfig. 2. Factory: Specifies the factory class of the message resource, default is: org.apache.struts.util.propertyMessageResourcesFactory class 3. Key: Specifies the property KEY used in the servletContext object stored by the resource bundle, default is the character defined by globals.Messages_Key CRRUME, only one resource bundle is allowed to use the default property. 4. NULL: Specifies how the Messagesources class handles the key of unknown messages. If true, return an empty string. If you are false, return the relevant string, default is false 5. Prameter: Specify the resource file name of Messagesources, if : ABApplicationResources, the actual file path is: Web-inf / class.properties. Such as: Access is: where the zxj table A string in the Messagesource resource file. 8. Plugin-in element Configure the Struts plug-in, the properties are as follows: 1. ClassName: The specified Struts plug-in class must implement org.apache.struts.Action.plugiin interface. Such as:

Postscript, multi-module configuration, available for multiple application applications different Struts-Config.xml

转载请注明原文地址:https://www.9cbs.com/read-130525.html

New Post(0)