多个XML文件的包含与继承关系

比如struts.xml文件里包含两个XML文件:global.xml和zhangsan.xml

struts.xml里:

1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
3 <struts>
4     <include file="global.xml"></include>
5     <include file="zhangsan.xml"></include>
6 </struts>    

global.xml里:(global.xml继承struts-default)

 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
 3 <struts>
 4     <package name="global" namespace="/" extends="struts-default">
 5         
 6         <!-- 全局异常的处理 -->
 7         <global-results>
 8             <result name="error">/error.jsp</result>
 9         </global-results>
10         <global-exception-mappings>
11             <exception-mapping result="error" exception="java.lang.Exception"></exception-mapping>
12         </global-exception-mappings>
13         
14     </package>
15 </struts>    

zhangsan.xml里:(zhangsan.xml继承global)

 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
 3 <struts>
 4     <package name="xsl" namespace="/" extends="global">
 5     
 6         <action name="testAction1" class="com.xsl.action.TestAction1">
 7             <!-- 
 8                 type属性不写,默认则为type="dispatcher"
 9                 tyoe="redirect"表示重定向到jsp
10                 type="chain"表示请求转发至另一个action
11              -->
12             <result name="test1" type="dispatcher">/success.jsp</result>
13             <result name="test2" type="redirect">/success.jsp</result>
14             <result name="test3" type="chain">testAction2_test1</result>
15             <result name="test4" type="redirectAction">testAction2_test2</result>
16         </action>
17         <!-- struts2.1这个版本要求action在跳转action时,不能写死action的名字 -->
18         <action name="testAction2_*" class="com.xsl.action.TestAction2" method="{1}">
19             <result>/success.jsp</result>
20         </action>
21 
22     </package>
23 </struts>    

 

转载于:https://www.cnblogs.com/xsl1995/p/6644549.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值