标签:aspectj object root time obj iter str proc poi
/** * session超时跳转登陆页面 * @author zhangdong * 2017年10月24日 */ @Aspect @Component public class SessionTimeoutAspect { private static Logger logger = Logger.getLogger(SessionTimeoutAspect.class); public SessionTimeoutAspect() { } @org.aspectj.lang.annotation.Pointcut("execution(* com.jsz.peini.controller..*.*(..))") public void controllerPointcut(){ } @Pointcut("execution(* com.jsz.peini.controller.mgr.UserLoginController..*(..))") public void rootPointcut(){//登录登出功能不需要Session验证 } @org.aspectj.lang.annotation.Pointcut("controllerPointcut()&&(!rootPointcut())") // @org.aspectj.lang.annotation.Pointcut("controllerPointcut()") public void sessionTimeOutPointcut(){ } @Around("sessionTimeOutPointcut()") public Object sessionTimeOutAdvice(ProceedingJoinPoint pjp) throws IOException { Object result = null; String targetName = pjp.getTarget().getClass().getSimpleName(); String methodName = pjp.getSignature().getName(); logger.info("----------------执行方法-----------------"); logger.info("类名:"+targetName+" 方法名:"+methodName); HttpServletResponse response = null; for (Object param : pjp.getArgs()) { if (param instanceof HttpServletResponse) { response = (HttpServletResponse) param; } } HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); HttpSession session = request.getSession(); if(session.getAttribute("MgrUserId")!=null){ try { result = pjp.proceed(); } catch (Throwable e) { e.printStackTrace(); } return result; } else{ logger.debug("Session已超时,正在跳转回登录页面"); PrintWriter writer = response.getWriter(); writer.write("<script>window.parent.location.href=‘/superOpAdmin.jsp‘</script>"); writer.flush(); writer.close(); } return result; }
标签:aspectj object root time obj iter str proc poi
原文地址:http://www.cnblogs.com/xdcr/p/7723078.html