Struts2 加入自定义拦截器后,原来能用的登录页出错

来源:互联网 发布:网络奇兵2怎么样 编辑:程序博客网 时间:2024/06/06 12:45

现象:

    原来可以使用的登录页,按照书p147的第一步和第五步加入自定义拦截器后,运行始终提示登录失败。

debug后发现,用户名和密码都没能传到action类中,也就是说参数注入失败了。

struts.xml中的配置:

<action name="login" class="com.ibm.etp.login.action.LoginAction">
            <!-- 配置跳转的url路径,如果是成功"success",可以使用默认不写 -->
            <result>success.jsp</result>
            <result name="failure">failure.jsp</result>
            <interceptor-ref name="timerInterceptor"></interceptor-ref>
       </action>

    如果删除拦截器timerInterceptor,则可以正常登录。

原因分析

    因此判定错误原因和这个新加入的自定义拦截器有关。

解决方法:

    在自定义拦截器前加入缺省的拦截器后,可以正常登录。所以使用了自定义拦截器的action要配置默认拦截器的引用,因为默认拦截器包含了参数的读取、session的管理等功能 

<action name="login" class="com.ibm.etp.login.action.LoginAction">
            <!-- 配置跳转的url路径,如果是成功"success",可以使用默认不写 -->
            <result>success.jsp</result>
            <result name="failure">failure.jsp</result>
            <interceptor-ref name="defaultStack"></interceptor-ref>
            <interceptor-ref name="timerInterceptor"></interceptor-ref>
        </action>

0 0
原创粉丝点击