全局的登录校验

        <interceptors>
            <interceptor name="SessionInterceptor"
                class="com.ROCKY.Interceptor.SessionInterceptor" />
            <interceptor-stack name="myStack">
                <interceptor-ref name="SessionInterceptor" />
                <interceptor-ref name="defaultStack" />
            </interceptor-stack>
        </interceptors>

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

        <global-results>
            <result name="login">/WEB-INF/jsp/login.jsp</result>
        </global-results>
public class SessionInterceptor extends  AbstractInterceptor{
    public String intercept(ActionInvocation actionInvocation)
    {
        Map session = actionInvocation.getInvocationContext().getSession();
        String account = (String)session.get(SessionConstant.USER_ACCOUNT);
        if (!StringUtils.isEmpty(account))
        {
            //检查数据库中是否有该用户
            try
            {
                return actionInvocation.invoke();
            }
            catch (Exception e)
            {
               //do exception
            }
        }
        return "login";
    }
}
原文地址:https://www.cnblogs.com/unixshell/p/3465981.html