weixin_42376755
2010-06-13 00:33 阅读 257
已采纳

为什么定义的拦截器死活都进不去!各位大虾看看吧!~~struts2的~~

拦截器的配置:

<interceptors>
        <interceptor name="authority"
            class="com.softeem.assurance.interceptor.AuthorityInterceptor ">
        </interceptor>
        <interceptor-stack name="myInterceptor">
            <interceptor-ref name="defaultStack"></interceptor-ref>
            <interceptor-ref name="authority" ></interceptor-ref>
        </interceptor-stack>
</interceptors>

    <default-interceptor-ref name="authority"></default-interceptor-ref>

    <global-results>
             <result name="login">/login.jsp</result>
    </global-results>

    <action name="user*"
        class="com.softeem.assurance.user.action.UserAction" method="{1}">
        <!-- 
        <result name="loginsuccess" type="redirect">userFindRole.action</result>
        <result name="loginfailure">/login.jsp</result>
         -->
        <interceptor-ref name="authority"></interceptor-ref>        
        <result name="failure">/login.jsp</result>
        <result name="baogao">/baogao.jsp</result>
        <result name="success">/main.jsp</result>
        <result name="listsuccess">/tab/userList.jsp</result>
        <result name="findByNameSuccess">/tab/userList.jsp</result>
        <result name="findByRoleSuccess">/tab/userList.jsp</result>
        <result name="userDeleteSuccess">userList.action</result>
        <result name="preSuccess">/tab/userAdd.jsp</result>
        <result name="addSuccess" type="redirect">userList.action</result>
        <result name="preModifySuccess">/tab/userModify.jsp</result>
        <result name="updateSuccess" type="redirect">userList.action</result>   
    </action>

</package>

拦截器代码:

public String intercept(ActionInvocation arg0) throws Exception {
System.out.println("interceptor: ");
ActionContext ac = arg0.getInvocationContext();
Object obj = ac.getSession().get("user");
if(obj != null){
return arg0.invoke();
}else{

        return "login";
    }
}

死活都输不出来我想要的内容

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

6条回答 默认 最新

  • 已采纳
    stackoverfl0w stackoverfl0w 2010-06-16 23:44


    class="com.softeem.assurance.interceptor.AuthorityInterceptor ">





    你把拦截器栈配错了,当然取不到值

    点赞 评论 复制链接分享
  • myali88 myali88 2010-06-13 10:47

    我测试过,拦截器已经调用,你想要的内容是什么?

    点赞 评论 复制链接分享
  • myali88 myali88 2010-06-13 22:39

    那奇怪了,你设置断点跟踪一下,看你的请求是否进入了Struts2,是否进入了拦截器。在FilterDispather的doFilter设断点。

    点赞 评论 复制链接分享
  • stang003 stang003 2010-06-14 12:58

    改成这样试试
    [code="java"]

    [/code]

    点赞 评论 复制链接分享
  • myali88 myali88 2010-06-14 15:32

    [quote]
    貌似没有这玩意
    [/quote]
    什么意思?你开发总会用个IDE吧,我一般就用Eclipse,当然有调试部分了。

    点赞 评论 复制链接分享
  • stackoverfl0w stackoverfl0w 2010-06-16 01:01

    进入登录判断前先这样
    Object action = ai.getAction();
    if (action instanceOf LoginAction || action instanceOf RegisterAction) {
    return ai.invoke();
    }

    点赞 评论 复制链接分享

相关推荐