STRUTS2 Study: The namespace of the configuration chapter

Source: Internet
Author: User

Pull the namespace out on the one hand because it's actually not an element, but just a attribute, which is already said, it's a attribute of the package. On the other hand, because this attribute was the first study I made when I contacted Struts2, I was very impressed, for these two reasons I decided to say it alone.

There is no concept of namespaces in Struts1, and through namespaces we can divide all action configurations into logical units, each with its own identifier prefix. Named controls can avoid conflicting action naming. There can be an action called "help" under each namespace, and there are different implementations, and of course it is best not to have two-name action under the same namespace. When a namespace prefix is present in the browser's URI, the tags are aware of the namespace, so we do not have to nest namespaces in forms and links.

The default namespace is the empty string "", which is the namespace when the namespace property is not set. When we match an action, we go to the namespace it specifies, and if we don't go to the default namespace, look for it. Struts2 also supports the root namespace ("/"), when a request directly requests a resource under the context path, STRUTS2 will first go to the namespace to look for a matching action, such as a request is http://server/myapp/ Bar.action, we first go to the "/" namespace to look for this action, and here is a sample of the namespace:

about how to map from a URI to an action I did some tests and found that I could follow one of the following rules:

1. Gets the URI of the request path, for example the URL is: http://server/myapp/path1/path2/path3/test.action

2. First look for the package namespace for/path1/path2/path3, if the package exists, then in

This package looks for the action named Test and executes it if found, otherwise the error is not present.

Package then go to step 3;

3. Look for the package namespace for/path1/path2, if the package is present, in this package

Search for the action named Test, if found to execute, otherwise error; If the package does not exist

Then go to step 4;

4. Look for the package namespace for/path1, and if this package exists, find in this package

Find the action named Test, if found to execute, otherwise error; If the package still does not exist,

Go to the package under the empty string and look for the action named Test, if you still can't find the Namaspace

, the page tip cannot find the action.

Here are a few special cases to illustrate, as follows:

1. If more than one package is matched, as in the above process, there are multiple namespace as/path1/path2/path3

Package, you find the action in the order in which the package appears, from the back-to-forward order until you find it.

2. If there is more than one action in a package with the same name attribute, then execution chases an action. For example, in the above process, there is a namespace for the/path1/path2/path3 package, which contains more than one action named Test, then select the last execution.

The above points are I through a number of tests summed up, do not know whether to summarize all possible situations, flaws, but also please correct me.

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.