登陆超时处理


捕获异常函数

jQuery.utilsAjaxException = {
    "ajaxException": function () {
        $(document).ajaxError(function (event, request, ajaxOptions, thrownError) {
            var str = 'timed_out_please_login';
            if (request.responseText === str) {
                window.location.href = 'exitView.hd'
            } else if (request.responseText === "Permission denied.") {
                resultTips("非法操作!", false);
            }
        });
    }
}

jQuery.checkSession = function () {
    $.post("checkSession.hd", {
        userId: $("#userSessionId").val()
    }, function (data) {
        if (data === "false") {
            window.location.href = 'exitView.hd';
        }
    });
};

index.html

   jQuery.checkSession();
   //异常处理
   jQuery.utilsAjaxException.ajaxException();

定义注解

@Target(ElementType.METHOD)//这个标注应用于方法
@Retention(RetentionPolicy.RUNTIME)//标注会一直保留到运行时
@Documented//将此注解包含在javadoc中
public @interface SessionControllerAnnotation {
    
}

定义切点

/**
 * 系统切点类,定义系统级的切点,
 *
 */
@Aspect
@org.springframework.stereotype.Component
public class SystemAspect {

    public SystemAspect() {
    }

    /**
     * 方法执行前的处理
     *
     * @param jp
     * @throws Exception
     */
    @Before(value = "@annotation(com.ithings.wp.session.SessionControllerAnnotation)")
    public void beforeAspect(JoinPoint jp) throws Exception {
        UserDto user = null;
        for (Object param : jp.getArgs()) {
            if (param instanceof HttpServletRequest) {
                user = (UserDto) ((HttpServletRequest) param).getSession().getAttribute(SystemConstant.SESSION_USER);
            }
        }
        if (CommUtils.isNull(user)) {
            throw new Exception("<globalError>operation_timed_out_please_login_again<globalError>");
        }
    }

}

配置

<aop:aspectj-autoproxy proxy-target-class="true" />



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值