您的位置:首页 > 编程语言 > Java开发

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

2013-01-08 23:14 483 查看
最近遇到了一个需求:有一个master struts.xml, 该文件中需要引入若该子模块中struts.xml.

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

首先问问google,结果是可行, 如下来自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标签,并填入全路径, 如下。

<?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标签,只填入文件名, 如下。

<?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的顶级路径中, 即:

childModule.jar
-com
--strutsTest
--.....
test-struts.xml

主struts配置文件与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>
结果: 成功!

可是为什么呢,暂记录,等有时间解释,并期待大牛的答疑。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐