多个应用跳转用户session存在缓存问题onbeforeunload

问题描述:

没有使用单点登录。

多个应用集成到一个门户中,但是多个tomcat应用时,portal中的session管理使用shiro,当不同应用通过菜单跳转时,每个菜单新进入时,进行登录授权,当离线时,用户登出,多个应用没有完全登出,存储session缓存问题。

解决方案:

使用 'onbeforeunload' 事件,当页面刷新或离开时,处理用户登出问题,清除session缓存问题。

代码:

/**
   * 页面跳出当前系统时调用,页面F5刷新也会调用
   * @param event
   */
window.onbeforeunload = function(event) {
/*
   event.target.activeElement
   刷新时, activeElement为 body
   跳转离开页面是  activeElement为 a 标签
*/

var targetUrl = event.target.activeElement.href;
if(targetUrl!=undefined && targetUrl.indexOf("?")>0){
   targetUrl = targetUrl.substring(0,targetUrl.indexOf("?"));
}

if(targetUrl == undefined){
    console.log("刷新")
}else {
    console.log("跳转")
    AjaxService.fetch({
         url: '../do/user/logout'
         }, 'globalLoading')
         .success(function (data) {
              if(data.resultCode.slice(-4) === '0000'){
                        window.sessionStorage.clear();
                    }
                });
    }
};

代码中使用event.target.activeElement.href判断页面是刷新还是跳转。当页面刷新时,event.target.activeElement属性下是<body>,当页面跳转时,点击菜单时,event.target.activeElement属性是<a>,这样通过event.target.activeElement.href是否有值来区分页面是刷新还是跳转来处理不同的业务逻辑。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值