Use the include tag in struts configuration file l to introduce another struts file in jar.

Source: Internet
Author: User

Recently encountered a requirement: There is a master struts. xml file which needs to be introduced if struts. xml.

However, these sub-modules are put into the classpath of the main module in the form of jar packages. Of course, their struts. XML is also in the jar. Can struts of the main module be introduced in this case?

First, ask Google. The result is feasible, as shown in the following figure:

 
<! Doctype struts public "-// Apache Software Foundation // DTD struts configuration 2.0 // en" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <include file = "home. XML "/> <include file =" hello. XML "/> <include file =" simple. XML "/> <include file ="/util/pojo. XML "/> <include file ="/COM/Initech/admin/admin-struts.xml "/> </struts>

Each encoded ded file must be in the same formatStruts. xml, Including
Doctype.The include files can be placed anywhere on the classpathAnd shoshould be referred to by that path by the "file" attribute.

Start to try:

The struts configuration file for the sub-module is named test-struts.xml, path is com/strutstest/mytest/

1. Use the include tag in the main struts configuration file and fill in the full path, as shown below.

 
<? XML version = "1.0" encoding = "UTF-8"?> <! Doctype struts public "-// Apache Software Foundation // DTD struts configuration 2.0 // en" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <include file = "struts-default.xml"/> <include file = "com/strutstest/mytest/test-struts.xml"/> </struts>

Result: Pu Jie

2. Use the include tag in the main struts configuration file and fill in only the file name, as shown below.

 
<? XML version = "1.0" encoding = "UTF-8"?> <! Doctype struts public "-// Apache Software Foundation // DTD struts configuration 2.0 // en" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <include file = "struts-default.xml"/> <include file = "test-struts.xml"/> </struts>

Result: Pu Jie

3. Use the include tag in the main struts configuration file, fill in only the file name, and put the struts configuration file in the sub-module into the top-level path of the jar, that is:

 
Childmodule. jar-com -- strutstest --... test-struts.xml

The main struts configuration file is the same as 2

 
<? XML version = "1.0" encoding = "UTF-8"?> <! Doctype struts public "-// Apache Software Foundation // DTD struts configuration 2.0 // en" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <include file = "struts-default.xml"/> <include file = "test-struts.xml"/> </struts>

Result: Successful!

But why? Keep a record for now, wait for time to explain, and look forward to Q & A from Daniel.

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.