strust2.5异常映射不起作用

时间:2018-06-28 05:13:34

标签: java servlets struts

我用过Struts 2.5.16,下面的代码是struts.xml内容:

<package name="default" extends="struts-default">
    <interceptors>
        <interceptor  name="authorizeInterceptor" class="web.comm.Interceptor.authorizeInterceptor"></interceptor>
    </interceptors>
    <action name="home">
        <result type="dispatcher">/view/index.jsp</result>
    </action>
    <action name="exp" class="web.comm.userAndAuthorize.commUserOp" method="jsonChangePass">
        <interceptor-ref name="authorizeInterceptor"/> 
        <exception-mapping result="Exception" exception="java.lang.Exception"/>
        <result name="Exception"  type="chain">/view/UserAndAuthorize/error.jsp</result>
        <allowed-methods>jsonChkLogin,jsonChangePass,createUser</allowed-methods>
    </action>

url是http://localhost/exp 遵循代码是jsonChangePass()的方法

public String jsonChangePass()throws Exception{

    int b=0,a=1;
    int c=a/b;

以下内容为chorme:

  

Struts问题报告Struts已检测到未处理的异常:

     

消息:/零...


请参阅网络上显示的内容,操作已在起作用。为什么异常映射不起作用?感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

由于您没有运行exception映射拦截器,因此无法使用。

在包中定义<interceptors>后,必须定义 all 拦截器:这不是加法元素,这是该包中使用的拦截器的声明。

IIRC,您可以使用<interceptor-ref>来获取defaultStack(或您打算使用的任何对象)并添加authorizeInterceptor