15-struts2 提供的异常处理


对于action中的操作,出现问题,直接抛出自定义异常。
在struts.xml文件中

    <global-results>
            <result name="error">/error.jsp</result>
        </global-results>
        
        <global-exception-mappings>
        <exception-mapping result="error"
            exception="cn.itcast.user.exception.FindByIdException">
        </exception-mapping>
    </global-exception-mappings>



这就可以让特定的异常,跳转到自定的页面。


原理:
struts2,默认加载的18个拦截器的第一个是exception这个拦截器,它没有做任何操作,
直接放行,,只是它将 invocation.invoke()操作使用try-catch进行了处理。

其它的拦截器,或是action只要向外抛出异常,exception拦截器就会将其捕获。

原文地址:https://www.cnblogs.com/1963942081zzx/p/6510955.html