struts配置文件l中使用include 标签 引入另外一个在jar中的struts文件

最近遇到了一个需求:有一个master struts.xml, 该文件中需要引入若该子模块中struts.xml.

但是这些子模块都以jar包的方式放入主模块的classpath中,当然它们的struts.xml也在jar中, 这种情形主模块的struts还能引入吗?

首先问问google,结果是可行, 如下来自struts官方网站:

  1. <!DOCTYPE struts PUBLIC  
  2.   "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"  
  3.   "http://struts.apache.org/dtds/struts-2.0.dtd">  
  4. <struts>  
  5.     <include file="Home.xml"/>  
  6.     <include file="Hello.xml"/>  
  7.     <include file="Simple.xml"/>  
  8.     <include file="/util/POJO.xml"/>  
  9.     <include file="/com/initech/admin/admin-struts.xml"/>  
  10. </struts>  
<!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 included file must be in the same format as struts.xml, including the DOCTYPE. The include files can be placed anywhere on the classpath and should be referred to by that path by the "file" attribute.

开始尝试:

子模块的struts配置文件 名为test-struts.xml, 路径为com/strutsTest/myTest/

1. 在主struts配置文件中使用include标签,并填入全路径, 如下。

  1. <?xml version="1.0" encoding="UTF-8" ?>  
  2. <!DOCTYPE struts PUBLIC  
  3. "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"  
  4. "http://struts.apache.org/dtds/struts-2.0.dtd">  
  5. <struts>  
  6.     <include file="struts-default.xml" />  
  7.     <include file="com/strutsTest/myTest/test-struts.xml" />  
  8. </struts>  
<?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>
结果:扑街

2. 在主struts配置文件中使用include标签,只填入文件名, 如下。

  1. <?xml version="1.0" encoding="UTF-8" ?>  
  2. <!DOCTYPE struts PUBLIC  
  3. "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"  
  4. "http://struts.apache.org/dtds/struts-2.0.dtd">  
  5. <struts>  
  6.     <include file="struts-default.xml" />  
  7.     <include file="test-struts.xml" />  
  8. </struts>  
<?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>
结果:扑街

3. 在主struts配置文件中使用include标签,只填入文件名 并将子模块中的struts配置文件放入jar的顶级路径中, 即:

  1. childModule.jar  
  2. -com  
  3.         --strutsTest  
  4.               --.....  
  5. test-struts.xml  
childModule.jar
-com
        --strutsTest
              --.....
test-struts.xml

主struts配置文件与2相同

  1. <?xml version="1.0" encoding="UTF-8" ?>  
  2. <!DOCTYPE struts PUBLIC  
  3. "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"  
  4. "http://struts.apache.org/dtds/struts-2.0.dtd">  
  5. <struts>  
  6.     <include file="struts-default.xml" />  
  7.     <include file="test-struts.xml" />  
  8. </struts>  
<?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>
结果: 成功!
注意如果要加载本地struts的xml必须使用全包名字。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值