jsp+js完成用户一定时间未操作就跳到登录页面

2023-02-23,,

		<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; UserInfo ui = UserInfo.getUserInfo(request);
//如果获取不到用户对象,跳转回登录页面
if(ui==null){
request.getRequestDispatcher("/WEB-INF/jsp/nosso.jsp").forward(request,response);
} %>

  

var lastTime = new Date().getTime();
var currentTime = new Date().getTime();
var timeOut =60 * 1000*10; //设置超时时间: 10分
$(function(){
$(document).mouseover(function(){
lastTime = new Date().getTime(); //更新操作时间
});
});
function testTime(){
currentTime = new Date().getTime(); //更新当前时间
if(currentTime - lastTime > timeOut){ //判断是否超时
// console.log("超时");
var base="<%=basePath+"nosso.do"%>";
window.location.href = base;
}
}
/* 定时器 间隔1秒检测是否长时间未操作页面 */
window.setInterval(testTime, 1000);

  

jsp+js完成用户一定时间未操作就跳到登录页面的相关教程结束。

《jsp+js完成用户一定时间未操作就跳到登录页面.doc》

下载本文的Word格式文档,以方便收藏与打印。