[Struts Related] Struts supports multiple configuration and modular support

xiaoxiao2021-03-06  40

We know that in Struts 1.0, we can only specify a configuration file for the ActionServlet in Web.xml, which is certainly no problem in our online teaching example, but in the actual application development process, there may be some troublesome . Because many developers may also need to modify the configuration file, but the configuration file can only be modified by one person, so it will definitely cause a certain extent, which will inevitably affect the development efficiency and the complaints of developers. In Struts 1.1, in order to solve this problem of parallel development, two solutions are proposed:

Support for multiple profiles support multiple profiles, which means that you can specify multiple XML configuration files for ActionServlets, with a comma-separated, such as the MailReader presentation example provided by Struts, using this method.

Action

org.apache.struts.Action.ActionServlet

config

/Web-inf/struts-config.xml, /web-inf/struts-config-registration.xml

1

This method can solve problems with conflicts, different developers can set their own action, Actionform, etc. in different configuration files (of course, not, each developer needs their own configuration file, can follow the system Function module is divided). However, there is still a potential problem, that is, there may be conflicts between different configuration files, because the few files will eventually merge together when the ActionServlet is initialized. For example, in Struts-Config.xml, a "Forward" named success is configured in Struts-Config-Registration.xml, it is also configured to conflict. In order to completely solve this conflict, the concept of module is introduced in Struts 1.1. A module is a separate subsystem that you can perform any of the required configurations, but also don't have to worry about conflicts with other profiles. Because we talked, ActionServlets were saved in different module information in different moduleconfig objects. To use the functionality of the module, you need to prepare the following: 1. Prepare a configuration file 2 for each module, configure the web.xml file, and notify the controller to decide to use multiple modules, you need to tell the controller, This needs to be configured in the web.xml file. Below is a typical multi-module configuration:

config

/web-inf/struts-config.xml

config / customer

/web-inf/struts-config-customer.xml

config / order

/Web-inf/struts-config-order.xml

To configure multiple modules, you need to increase the of the module on the original (referred to in Struts 1.1 to the default module). Where is in the form of config / xxx, where xxx is the corresponding module name, or the configuration file corresponding to the module. The above example shows that the application has three modules, which are default modules, Customer, and Order, which correspond to different profiles. 3. Prepare resources such as ActionForm, Action, and JSP needed by each module, but to note that the appearance of the module also brought a problem, that is, how to forward between different modules? There are two ways to realize the forwarding between modules, one is defined in (globally or local), and the other is to use org.apache.struts.Actions.SwitchChaction. Below is a global example:

...

...

ContextRelative = "true"

Path = "/ moduleb / index.do"

REDIRECT = "true" />

...

...

It can be seen that only the module name needs to be added prior to the original Path property, and the ContextRelative property is set to true. In addition, you can define a similar local in .

TYPE = "com.ncu.test.loginaction"

Name = "loginform"

Scope = "request"

Input = "tile.userlogin"

Validate = "True">

If you already in other modules, you need to turn back to the default module, which should be similar to the following, that is, the module name is empty.

In addition, you can also use org.apache.struts.Actions.switch, for example:

...

TYPE = "org.apache.struts.Actions.switch" />

...

...

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

New Post(0)