zoukankan      html  css  js  c++  java
  • session 超时跳转登陆页面

    /**
    * 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; 
    } 
    

      

  • 相关阅读:
    Codeforces Round #652 (Div. 2)
    Codeforces Round #651 (Div. 2)
    The 2017 China Collegiate Programming Contest, Qinhuangdao Site
    2017中国大学生程序设计竞赛-哈尔滨站
    Codeforces Global Round 8
    [CF768D] Jon and Orbs
    2020牛客暑期多校训练营(第一场)I
    2020牛客暑期多校训练营(第一场)F
    [HDU5769] Substring
    [PA2010] Riddle
  • 原文地址:https://www.cnblogs.com/xdcr/p/7723078.html
Copyright © 2011-2022 走看看