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.