怎么判断用户非法退出,比如用户关闭了浏览器,我怎么能够知道用户退出了

怎么判断用户非法退出,比如用户关闭了浏览器,我怎么能够知道用户退出了,第1张

jsp关闭浏览器时,清空session的方式如下:

function windowonUnload()
{
var newWindow;
if((windowscreenLeft>=10000 && windowscreenTop>=10000)||eventaltKey)
{ newWindow=windowopen('destorysjsp','网页名称','width=0,height=0,top=4000,left=4000');//新窗口将在视区之外打开 newWindowopener=null; sleep(5000); newWindowclose();//新窗口关闭 }
}
function sleep(milisecond)
{ var currentDate,beginDate=new Date(); var beginHour,beginMinute,beginSecond,beginMs; var hourGaps,minuteGaps,secondGaps,msGaps,gaps; beginHour=beginDategetHours(); beginMinute=beginDategetMinutes(); beginSecond=beginDategetSeconds(); beginMs=beginDategetMilliseconds(); do {   currentDate=new Date();   hourGaps=currentDategetHours() - beginHour;   minuteGaps=currentDategetMinutes() - beginMinute;   secondGaps=currentDategetSeconds() - beginSecond;   msGaps=currentDategetMilliseconds() - beginMs;   if(hourGaps<0) hourGaps+=24; //考虑进时进分进秒的特殊情况   gaps=hourGaps3600+ minuteGaps60+ secondGaps;   gaps=gaps1000+msGaps; }while(gaps<milisecond); }
其中红色部分为你指向清除session的JSp页面。
如下:
 
<%@ page contentType="text/html; charset=GBK" %> <%@ page language="java" import="javalang"%> <jsp:useBean id="login" scope="page" class="comutilLogin"/> <% sessionremoveAttribute("username"); sessionremoveAttribute("userid"); sessionremoveAttribute("power"); sessionremoveAttribute("flag"); %>
这样,在每个后台页面引用一个这个JS,就可以实现了。

if (cmdequals("login")) {//登入 *** 作
这句发生空指针的情况是cmd是null,因为从传递的参数中没有cmd这个参数,所以为空
标准的写法是:
if ("login"equals(cmd)) {//登入 *** 作
如果cmd为空也不会发生异常,以后遇到类似的情况都可以这么写,然后把参数打印出来便于分析问题。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/13390269.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-07-27
下一篇 2023-07-27

发表评论

登录后才能评论

评论列表(0条)

保存