捕获异常函数
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" />