Struts2的声明式异常处理

1、例如SSH中在数据库连接失败时进行增删查改,会出现org.springframework.transaction.CannotCreateTransactionException的问题

(1)、在可能出现错误的方法throws 

    public Session getSession() throws CannotCreateTransactionException {
        return sessionFactory.getCurrentSession();
    }

(2)、struts.xml

        <global-results>
            <result name="sqlexception">/sqlexception.jsp</result>
        </global-results>
        <global-exception-mappings>
            <exception-mapping result="sqlexception"
exception="org.springframework.transaction.CannotCreateTransactionException"></exception-mapping>
        </global-exception-mappings>

如果出现这个exception,回转到/sqlexception.jsp。

Done

posted @ 2014-08-09 15:58  行云有影  阅读(133)  评论(0编辑  收藏  举报