首页 > 其他 > 详细

struts2 interceptor

时间:2014-01-25 20:05:27      阅读:468      评论:0      收藏:0      [点我收藏+]

struts.xml configuration

bubuko.com,布布扣
<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"/>
bubuko.com,布布扣

user-defined interceptor

bubuko.com,布布扣
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;
    }

}
bubuko.com,布布扣

struts2 interceptor

原文:http://www.cnblogs.com/BrightMoon/p/3533347.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!