Struts2 Study Notes (3): search order and default value of action names

Source: Internet
Author: User

Suppose our access address is: http: // localhost: 8080/struts2/test/helloworld, then change it to http: // localhost: 8080/structs2/test/SDF/SFS/AAA/helloworld can still be accessed?

The answer is yes.

Strange. Why?

Let's take a look at the search sequence of action names.

1. Obtain the URI of the Request Path. For example, the URL is http: // server/struts2./Path1/path2/path3/Test. Action

 

2. First, find the namespace/Path1/path2/path3If the package does not exist, perform Step 3. If the package exists, search for the action named test in the package, when no action is found in the package, the action is directly searched in the package of the default namaspace (the default namespace is an empty string "").If the action cannot be found in the package of the default namaspace, the page prompts that the action cannot be found.

 

3. Find the namespace/Path1/path2If the package does not exist, go to Step 4. If the package exists, find the action named test in the package, when no action is found in the package, the system will directly go to the default namaspace package to find the action named test,The action cannot be found in the package of the default namaspace. The page prompts that the action cannot be found.

 

4. Find the namespace/Path1If the package does not exist, perform Step 5. If the package exists, search for the action named test in the package, when no action is found in the package, the system will directly go to the default namaspace package to find the action named test,The action cannot be found in the package of the default namaspace. The page prompts that the action cannot be found.

 

5. Find the package whose namespace is/. If this package exists, search for the action named test in this package,When the action cannot be found in the package or the package does not exist, the action will be searched in the package of the default namaspace. If the action still cannot be found, the page prompts that the action cannot be found..

 

 

Let's take a look at the default values in action:
    action   name  =" helloworld "  class   =" com. jim. action. helloworldaction "  method  =" execute " > 
result name =" success " >/WEB-INF/page/hello. JSP result >
action >

1> if no class is specified for action, actionsupport is used by default.

2> if no method is specified for the action, the execute () method in the action is executed by default.

3> If the name attribute of result is not specified, the default value is success.

Therefore, if we write:
 
<ActionName= "Test">
<Result>/WEB-INF/page/Hello. jsp</Result>
</Action>

when we access the action test, it will automatically jump to the following JSP page

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.