struts2对异常的处理机制

 为了使用struts2中的异常处理机制,我们必须打开struts2的异常映射功能,开启异常映射功能需要的一个拦截器,下面的代码片段来自struts-default.xml,在该配置文件中已经开启了struts2的异常映射

 <interceptors> 
    <interceptor name="exception" class="com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor"></interceptor>
            <interceptor name="permission" class="com.ultratest.oa.interceptor.LoginInterceptor"> 
            </interceptor> 
            <!-- 拦截器栈 --> 
            <interceptor-stack name="permissionStack"> 
           
               <interceptor-ref name="exception"></interceptor-ref>
                <interceptor-ref name="permission" /> 
                <interceptor-ref name="defaultStack" /> 
            </interceptor-stack> 
        </interceptors> 
        <default-interceptor-ref name="permissionStack"></default-interceptor-ref>
        
         <!-- 定义全局Result --> 
        <global-results> 
            <!-- 当返回login视图名时,转入/login.jsp页面 --> 
           
            <result name="login">/index.jsp</result>
            <result name="permissionError">/permissionError.jsp</result>
            <result name="flowError">/flowError.jsp</result>
            <result  name="error">/error.jsp</result>
            <result  name="oaError">/oaError.jsp</result>
        </global-results>
       <global-exception-mappings>
       <exception-mapping result="oaError" exception="com.ultratest.oa.exception.OAException"></exception-mapping>
        <exception-mapping result="oaError" exception="java.lang.Exception"></exception-mapping>

</global-exception-mappings>

 

请注意:golobal-exception-mappings 配置在global-results的后面

在页面oaError页面上使用

    异常信息:<s:property value="exception.message"/><br/>
异常栈信息:<s:property value="exceptionStack"/>

使用这两个标签查看异常信息

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值