码迷,mamicode.com
首页 > 其他好文 > 详细

session 超时跳转登陆页面

时间:2017-10-24 14:09:05      阅读:116      评论:0      收藏:0      [点我收藏+]

标签: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; 
} 

  

session 超时跳转登陆页面

标签:aspectj   object   root   time   obj   iter   str   proc   poi   

原文地址:http://www.cnblogs.com/xdcr/p/7723078.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!