struts2.0中如何将struts.xml文件分成多个配置文件

使用<include>标签重用配置文件
在struts2中提供了一个默认的struts.xml文件,但如果package、action、interceptors等配置比较多时,都放到一个struts.xml文件不太容易维护。因此,就需要将struts.xml文件分成多个配置文件,然后在struts.xml文件中使用<include>标签引用这些配置文件。这样做的优点如下:
结构更清晰,更容易维护配置信息。
配置文件可以复用。如果在多个web程序中都使用类似或相同的配置文件,那么可以使用<include>标签来引用这些配置文件,这样可以减少工作量。
假设有一个配置文件,文件名为newstruts.xml,代码如下:
<?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>
    

        <action name="submit"  class="action.moresubmitaction">
            <result name="save" >
                /result.jsp
            </result>
            <result name="print">
                /result.jsp
            </result>
        </action>            
    </package>    
</struts>
则struts.xml引用newstruts.xml文件的代码如下:
<?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="newstruts.xml"/>
    

      
    </package>    
</struts>

大家要注意一下,用<include>引用的xml文件也必须是完成的struts2的配置。实际上<include>在引用时是单独解析的xml文件,而不是将被引用的文件插入到struts.xml文件中。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值