Struts2处理异常

作者在 2010-11-02 15:43:41 发布以下内容
Action:
public String execute() throws Exception {
        if (this.getUserName().equals("angel") && this.getPassword().equals("123")) {
            this.setResult(true);
            return SUCCESS;
        } else if (this.getUserName().equals("aa")) {
            throw new SQLException("the UserException happened");
        } else {
            throw new Exception();
        }
}
struts.xml中的配置:
<action name="exceptionAction" class="action.ExceptionAction">
            <exception-mapping result="exception" exception="SQLException" />
            <exception-mapping result="exception" exception="Exception" />
            <result name="exception">/exception.jsp</result>
</action>
最后的异常显示:
<s:property value="exception.message" /><p/>
<s:property value="exceptionStack" />
默认分类 | 阅读 636 次
文章评论,共0条
游客请输入验证码