struts2-异常处理
<struts>
1: global-result 必须要写在global-exception 的前面
<constant name="struts.devMode" value="true"></constant>
<package name="addUser" extends="struts-default">
<global-results>
<result name="error">/error.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping result="error" exception="java.lang.Exception"></exception-mapping>
</global-exception-mappings>
</package>
<package name="admin" namespace="/admin" extends="addUser" >
<action name="index">
<result>/admin/index.html</result>
</action>
</package>
</struts>
2: 在后台代码里就应该按照如下的写法:但是在方法的后面一定要加上throws XX异常。
public List<Category> list() throws SQLException {
try {
xx 方法;
}
} catch (SQLException e) {
e.printStackTrace();
throw(e);
}
}