Several Problems of multi-module struts applications (and some solutions)

Source: Internet
Author: User

Struts 1.1 supports applyingProgramIt is divided into multiple modules, each of which can be seen as an independent application. At the same time, I also found some problems. For example, if a struts application is divided into about ten modules, we do not know how to solve the following problems:

1. Because verification is required, "errors. required = {0} is required. "and other resources, is there only a method defined in a file?

2, with tiles, to define almost the same definition in each module corresponding to the tiles-defs.xml, is there a way to define only in a file? (I tried to define a definition in the default module, and then extends in the module, but no, extends seems to only find the current module)

3. When using exceptionhandler, why do I specify the bundle attribute in the exception tag or only find resources in the current module? I want to declare some repeated Exception Handling in a file, such as notloginexception and nosuchobjectexception, and their corresponding keys point to resources in the same resource file (using the bundle attribute). How can this problem be achieved?

After a period of exploration, the first and third problems are basically solved. In fact, they can be seen as the same type of problems, that is, the problems of resources. When defining a resource file in a struts-config-xxx.xml, you can specify a factory property to use the default "org. Apache. Struts. util. propertymessageresourcesfactory" class from time to time. My solution is to customize a custommessageresourcesfactory class, and pass multiple resource files in the form of comma-separated parameters (namely, the parameter attribute of message-resources) to it, resources are traversed to search for them. At the same time, you also need to customize a custommessageresources class. Its getmessage () method is the key to searching resources.CodeThe factory only parses the comma-separated parameter structure and returns the custommessageresources instance.

The custommessageresourcesfactory code is relatively simple, as shown below:

Package EG;

Import java. util. arrays;

Import org. Apache. Struts. util. messageresources;
Import org. Apache. Struts. util. messageresourcesfactory;

Public class custommessageresourcesfactory extends messageresourcesfactory {

Public messageresources createresources (string config ){

Return   New Custommessageresources (arrays. aslist (config. Split ( " , " )));
}

}

Custommessageresources is a little more complicated, but fortunately, I found a class that fully meets my requirements on the Internet. Here, if the link has expired, please contact me.

In this way, in the struts-config-xxx.xml of each module, as long as the resource file is defined as below, the ability to share resources can be achieved, where errorresources is the error information resources required by all modules:

< Message-Resources Factory = "Eg. custommessageresourcesfactory"  
Parameter = "Eg. applicationresources, eg. errorresources"   />

The above referencesArticleBytes.

The second problem has not been solved yet. You may need to modify the handler implementation.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.