struts2中的异常处理
Struts2 中的异常处理?
异常有几种类型:
1.意外的错误
2.改变工作流
3.通过与用户交互来恢复
4.显示错误
下面分别对这几种异常的解析
1.意外的错误
<package name="itcast" namespace="/test" extends="struts-default"> <global-results> <result name="unknown">/WEB-INF/jsp/error.jsp</result> <result name="dberror">/WEB-INF/jsp/dberror.jsp</result> </global-results> <global-exception-mappings> <exception-mapping result="unknown" exception="java.lang.Exception"></exception-mapping> <exception-mapping result="dberror" exception="java.sql.SELException"></exception-mapping> </global-exception-mappings> </package>
<global-results> <result name="login">/WEB-INF/jsp/login.jsp</result> <result name="noaccess">/WEB-INF/jsp/noaccess.jsp</result> </global-results> <global-exception-mappings> <exception-mapping result="login" exception="UserNotAuthentivatedException"></exception-mapping> <exception-mapping result="noaccess" exception="ActionNotAllowedException"></exception-mapping> </global-exception-mappings>
<action name="helloworld" method="execute" > <result name="success">/WEB-INF/page/hello.jsp</result> <result name="dupPk">/WEB-INF/jsp/user/findUser-success.jsp</result> <exception-mapping result="dupPk" exception="org.hibernate.exception.ConstraintViolationException"></exception-mapping> </action>
<s:if test="exception!=null"> <s:text name="errorMessage"/> </s: if>
<s:property value="exception" /> <s:property value="exceptionStack" />