[Migration file] main configuration file overview of struts2 [struts. xml]

Source: Internet
Author: User

This document records the main configuration files, storage locations, and notes of struts2.

(In fact, these configuration files work under the class folder, but all files placed in the SRC folder will be copied to the corresponding class folder during eclipse compilation .)

Configuration File Name Storage location Remarks

Struts. xmlStruts2 default configuration file in the SRC folder

L you can use <include> to include other struts configuration files.

L inherit other packages in <package> to have configurations of other packages.

L it is best to add a <result> with the name "input" to each action, which is the default return value for errors.

L inheritance of <package>:

If one package inherits from another package, the. xml configuration file of the other package must be included. Only one exception is that the struts-default.xml does not need to be loaded when the structs-default package is inherited. Because struts. XML is by default containing the struts-default.xml.

During package inheritance, the package sequence is irrelevant. The previous package can inherit the subsequent package.

(It seems that there is an "authoritative guide" to say that this is still the interceptor configuration, which is sequential and has a sequence. At least for my tests, package inheritance is definitely not sequential)

Take an example. There are three configuration files:

Struts-base.xml, struts-middle.xml, and Struts. xml

 

Struts-base.xmlConfiguration snippets

 

<Struts>

<Package name = "base" extends = "struts-Default" abstract = "true">

</Package>

</Struts>

Struts-middle.xmlConfiguration snippets

 

<Struts>

<Package name = "Middle" extends = "base" abstract = "true">

</Package>

</Struts>

Struts. xmlConfiguration snippets

 

<Struts>

<Package name = "registaction" extends = "TOP">

<Action> </Action>

</Package>

<Package name = "TOP" extends = "Middle">

</Package>

<Include file = "struts-middle.xml"> </include>

<Include file = "struts-base.xml"> </include>

</Struts>

 

The configuration in struts. xml shows that the package inheritance order is completely the opposite to the position defined by the package, but the execution is correct.

Also note that in the struts-base.xml, the package named base directly inherits Struts-default without introducing the struts-default.xml. You might assume that each configuration file automatically contains the struts-default.xml. However, I personally think this is because of struts. XML contains both struts-default.xml and struts-base.xml, which are actually in the same configuration file, so it is not surprising that the base package can inherit Struts-default directly, the middle and base packages are the same.

 

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.