导读:
struts-config.xml 这里我用的是局部的处理方法。
对所有的Action的异常都可以捕捉。
它匹配到了Action抛出的异常就定位到 页面。匹配通过 实现
attribute="myExceptionForm"
name="myExceptionForm"
path="/myException"
scope="request"
type="com.yourcompany.struts.action.MyExceptionAction"> attribute="myExceptionForm"
name="myExceptionForm"
path="/myException"
scope="request"
type="com.yourcompany.struts.action.MyExceptionAction">
key="button.save"
path="/error/struts-error.jsp"
type="java.lang.Exception" />
=================================================
MyExceptionAction.java 中直接抛出一个异常
public class MyExceptionAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
MyExceptionForm myExceptionForm = (MyExceptionForm) form;
String exception = myExceptionForm.getException();
throw new Exception(exception);
}
}
============================================
/error/struts-error.jsp
This is struts-error page.
struts-config.xml 这里我用的是局部的处理方法。
对所有的Action的异常都可以捕捉。
它匹配到了Action抛出的异常就定位到 页面。匹配通过 实现
attribute="myExceptionForm"
name="myExceptionForm"
path="/myException"
scope="request"
type="com.yourcompany.struts.action.MyExceptionAction"> attribute="myExceptionForm"
name="myExceptionForm"
path="/myException"
scope="request"
type="com.yourcompany.struts.action.MyExceptionAction">
key="button.save"
path="/error/struts-error.jsp"
type="java.lang.Exception" />
=================================================
MyExceptionAction.java 中直接抛出一个异常
public class MyExceptionAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
MyExceptionForm myExceptionForm = (MyExceptionForm) form;
String exception = myExceptionForm.getException();
throw new Exception(exception);
}
}
============================================
/error/struts-error.jsp
This is struts-error page.
这里的错误信息是从消息资源文件中,通过
匹配的取出的。
===========================================
ApplicationResources.properties
button.save=save
#错误提示信息
本文转自
http://hi.baidu.com/qdcoder/blog/item/348bc959e442da2e2934f072.html