• 周五. 9月 30th, 2022

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

struts2 interceptor

admin

11月 28, 2021

struts.xml configuration

<interceptors>
<interceptor name="AuthenticationInterception" class="com.vincent.faceLook.interceptor.AuthenticationInterception"/>
<interceptor-stack name="oaInterceptorStack">
<interceptor-ref name="AuthenticationInterception"/>
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="oaInterceptorStack"/>

user-defined interceptor

package com.vincnet.jusns.interceptor;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.vincnet.jusns.entity.User;

public class AuthenticationInterception extends AbstractInterceptor {

    @Override
    public String intercept(ActionInvocation ai) throws Exception {
        // TODO Auto-generated method stub
        //String interceptInfo = "concent";
        String interceptInfo = null;
        User user = (User) ai.getInvocationContext().getSession()
                .get("currentUser");
        if (user != null) {
            ai.invoke();
        } else {
            String method = ai.getProxy().getMethod();
            if("login".equals(method)){
                ai.invoke();
            }else{
                interceptInfo = "user not login";
            }
        }
        return interceptInfo;
    }

}

发表回复

您的电子邮箱地址不会被公开。