struts2拦截器不起作用

来源:互联网 发布:淘宝里的金牌卖家 编辑:程序博客网 时间:2024/06/07 22:45

struts.xml 中

<interceptors>
            <interceptor name="login" class="com.lz.interceptor.CheckLoginInterceptor"/>
            <interceptor-stack name="teamwareStack">
                <interceptor-ref name="login"/>
                <interceptor-ref name="defaultStack"/>
            </interceptor-stack>
</interceptors>


实现类:

package com.lz.interceptor;


import java.util.Map;


import com.lz.action.UsersAction;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;


public class CheckLoginInterceptor extends AbstractInterceptor {


public static final String LOGIN_KEY = "login";

@Override
public String intercept(ActionInvocation arg0) throws Exception {


Object action = arg0.getAction();

if (action instanceof UsersAction) {
            return arg0.invoke();
        }

Map<String, Object> session = arg0.getInvocationContext().getSession();

String login = (String)session.get(LOGIN_KEY);

if(login != null && login.length() > 0){
return arg0.invoke();
} else{
return "error";
}

}


}

0 0
原创粉丝点击