struts2 interceptor

Struts.xml配置与自定义拦截器
博客提及struts.xml配置和用户自定义拦截器相关内容,转载自https://www.cnblogs.com/BrightMoon/p/3533347.html ,聚焦于信息技术领域的后端开发知识。

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;
    }

}

 

 

 

 

转载于:https://www.cnblogs.com/BrightMoon/p/3533347.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值