1.自定义异常处理类
public class SysException extends Exception {
private String message;
public String getMessage() {
return message;
}
public SysException(String message) {
this.message = message;
}
}
2.在struts.xml中进行全局异常的配置
<!-- 配置全局异常 sysException,error -->
<global-results>
<result name="sysException">/WEB-INF/pages/error.jsp</result>
<result name="error">/WEB-INF/pages/error.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping result="sysException" exception="自己定义的异常类的全路径名"/>
<exception-mapping result="error" exception="java.lang.Exception"/>
</global-exception-mappings>
3.加入错误处理页面pages/error.jsp
本文介绍如何通过自定义异常处理类实现Struts框架中的全局异常处理。具体包括创建自定义异常类SysException,并在struts.xml中配置全局异常映射,最后通过error.jsp页面展示错误信息。
334

被折叠的 条评论
为什么被折叠?



