结果:我定义了全局错误拦截器,也指定了界面,也拦截到了错误。但是就是不能跳转到我的页面
定义全局拦截器
struts.xml
   <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="struts-iperson" extends="struts-default">
<interceptors>
<interceptor name="checkLogin"
class="com.iperson.common.CheckLoginInterceptor" />
<interceptor name="checkException"
class="com.iperson.common.ExceptionInterceptor" />

<!-- check user is login -->
<interceptor-stack name="ipersonCheckLogin">
<interceptor-ref name="checkException" />
<interceptor-ref name="checkLogin" />
<interceptor-ref name="defaultStack" />
</interceptor-stack>

</interceptors>

<default-interceptor-ref name="ipersonCheckLogin" />
<global-results>
    <result name="login" type="redirectAction">login</result>
<result name="error">/WEB-INF/global/error404.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="com.iperson.common.SystemException" result="error"/>
</global-exception-mappings>
</package>
</struts>
---------拦截器-------ExceptionInterceptor.java---------------------
package com.iperson.common;import java.io.IOException;
import java.sql.SQLException;import org.springframework.dao.DataAccessException;import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.interceptor.PreResultListener;public class ExceptionInterceptor extends AbstractInterceptor  { private static final long serialVersionUID = 1L;

@Override
public String intercept(ActionInvocation arg0) throws Exception {
String result = ""; try {
result = arg0.invoke();
} catch (DataAccessException ex) { throw new SystemException("数据库操作失败!"); } catch (NullPointerException ex) { throw new SystemException("空指针,调用了未经初始化或者是不存在的对象!"); } catch (IOException ex) { throw new SystemException("IO读写异常!"); } catch (ClassNotFoundException ex) { throw new SystemException("指定的类不存在!"); } catch (ArithmeticException ex) { throw new SystemException("数学运算异常!"); } catch (ArrayIndexOutOfBoundsException ex) { throw new SystemException("数组下标越界!"); } catch (IllegalArgumentException ex) { throw new SystemException("调用方法的参数错误!"); } catch (ClassCastException ex) { throw new SystemException("类型强制转换错误!"); } catch (SecurityException ex) { throw new SystemException("违背安全原则异常!"); } catch (SQLException ex) { throw new SystemException("操作数据库异常!"); } catch (NoSuchMethodError ex) { throw new SystemException("调用了未定义的方法!"); } catch (InternalError ex) { throw new SystemException("Java虚拟机发生了内部错误!"); } catch (Exception ex) { throw new SystemException("程序内部错误,操作失败!"); } return result;
}}
----------最后相应类--------SystemException.java----------------------------
package com.iperson.common;public class SystemException extends RuntimeException { private static final long serialVersionUID = 1L;
public SystemException(String systemMessage){
super(createSystemMessage(systemMessage));
} public SystemException(Throwable throwable){ super(throwable); } public SystemException(Throwable throwable, String frdMessage){ super(throwable); } private static String createSystemMessage(String msgBody){
String prefixString = "抱歉";
String suffixStr="请稍后再试或者与管理员联系";
StringBuffer sbMsg = new StringBuffer();
sbMsg.append(prefixString);
sbMsg.append(msgBody);
sbMsg.append(suffixStr);
return sbMsg.toString(); }
}
------------------上面和网上的例子一模一样的。但是我的去不能跳转。不知道为什么Struts

解决方案 »

  1.   

    <default-interceptor-ref name="ipersonCheckLogin" />
    你使用这个默认拦截器的时候,系统默认的拦截器就会被覆盖,把系统默认的拦截器放在ipersonCheckLogin拦截器中就可以了。
      

  2.   

    <interceptor-ref name="defaultStack" /> 在里面引用的。默认拦截器。
    它其实是拦截了的,就是不跳转。很多天了一直也不知道,方便的话能清楚告诉么。Thks