Step 1
timeout.js
(function($){
$.fn.idleTimeout = function(options) {
var defaults = {
inactivity: 1500000, //25 Minutes
noconfirm: 10000, //10 Seconds
sessionAlive: 30000, //10 Minutes
redirect_url: '/view/LoginError?errorCode=3',
click_reset: true,
alive_url: '/view/KeepSessionAlive',
logout_url: '/view/LoginError?errorCode=3'
}
//##############################
//## Private Variables
//##############################
var opts = $.extend(defaults, options);
var liveTimeout, confTimeout, sessionTimeout;
var initialTimer;
var modal = "<div id='modal_pop'><p>You will be logged out of Expert AdminSpace in <span>5:00</span> minutes. </p></div>";
//##############################
//## Private Functions
//##############################
function setTimer(){
var sec = 300;
var timer = setInterval(function() {
sec--;
var m = Math.floor(sec / 60);
var s = Math.floor(sec % 60);
$('#modal_pop span').text(
(m > 0 ? m + ' minute' + ((m > 1) ? 's ' : ' ') : '') +
s + ' second' + ((s > 1) ? 's' : ''));
}, 1000);
}
var start_liveTimeout = function()
{
clearTimeout(liveTimeout);
clearTimeout(confTimeout);
liveTimeout = setTimeout(logout, opts.inactivity);
if(opts.sessionAlive)
{
clearTimeout(sessionTimeout);
sessionTimeout = setTimeout(keep_session, opts.sessionAlive);
}
}
var logout = function()
{
confTimeout = setTimeout(redirect, opts.noconfirm);
initialTimer = setTimer();
$(modal).dialog({
buttons: {"Stay Logged In": function(){
$(this).dialog('close');
stay_logged_in();
}},
modal: true,
title: 'Expert AdminSpace'
});
}
var redirect = function()
{
if(opts.logout_url)
{
$.get(opts.logout_url);
}
window.location.href = opts.redirect_url;
}
var stay_logged_in = function(el)
{
start_liveTimeout();
if(opts.alive_url)
{
$.get(opts.alive_url);
}
}
var keep_session = function()
{
$.get(opts.alive_url);
clearTimeout(sessionTimeout);
sessionTimeout = setTimeout(keep_session, opts.sessionAlive);
}
//###############################
//Build & Return the instance of the item as a plugin
// This is basically your construct.
//###############################
return this.each(function() {
obj = $(this);
start_liveTimeout();
if(opts.click_reset)
{
$(document).bind('click', start_liveTimeout);
}
if(opts.sessionAlive)
{
keep_session();
}
});
};
})(jQuery);
step 2:
in web.xml
<servlet>
<servlet-name>KeepSessionAlive</servlet-name>
<servlet-class>com.filogix.expert.view.uam.KeepSessionAlive</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>KeepSessionAlive</servlet-name>
<url-pattern>/view/KeepSessionAlive</url-pattern>
</servlet-mapping>
step 3
package com.filogix.expert.view.uam;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import com.filogix.expert.view.ViewServlet;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: </p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class KeepSessionAlive
extends ViewServlet {
public static final Logger log = Logger.getLogger(KeepSessionAlive.class);
//Clean up resources
public void destroy() {
}
@Override
public void processRequest(HttpServletRequest request,
HttpServletResponse response, int method) throws ServletException,
IOException {
// TODO Auto-generated method stub
try {
response.setContentType("text");
response.setHeader("Cache-Control", "no-cache");
response.getWriter().write("Y");
} catch (Throwable t){
log.error(t);
}
}
}
分享到:
相关推荐
(2)打开tomcat/conf/web.xml文件 ,找到 <session-timeout>30</session-timeout> 一行, 把30改成 1-5的数(作用设置是session超时时间,用于扑捉用户直接关闭浏览器时的下 线状态) 完成以上两步后打开tomcat即可在...
该源码是asp.net+jquery+ajax简单留言板例子 v1.1,该源码是本例采用asp.net C#+ jquery1.4.1 +ajax的实现 本例主要用aspx文件请求 还可以用ashx处理 ajax返回类型也很多如: dataType: "xml", dataType: "json", ...
用户登录与退出功能应用在很多地方,而在有些项目中,我们需要使用Ajax方式进行登录,登录成功后只刷新页面局部,从而提升了用户体验度。本文将使用PHP和jQuery来实现登录和退出功能。 准备数据库 本例我们使用...
基于这个问题,我们使用JQuery+Ajax技术,其实MUI中也自带ajax技术。 实现过程: webForm代码: function login() { var name = document.getElementById(username).value; //获取用户名 var password = ...
session timeout/logout using php and AJAX :
Extending WebSphere Portal Session Timeout E文
tomcat+httpservlet+session+cookie+jsp+filter
资源包括 tomcat7+jdk1.7+redis session共享; tomcat8+jdk1.8+redis session共享; jar包+配置文件都有
NULL 博文链接:https://shmilywzc.iteye.com/blog/1203141
PHP以其易用性、开源性等特点成为一种非常热门的... ... ... 第2章 调试环境的安装.ppt ... 第11章 Session与Cookie.ppt ... 第19章 PHP+AJAX留言簿程序.ppt ... 第20章 PHP+AJAX聊天室程序.ppt 第21章 用PHP+Ajax制作论坛.ppt
该资源内项目源码是个人的毕设,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分95分 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如...
request.setAttribute("message", "Session timeout!"); response.sendRedirect(response.encodeRedirectURL("/ajaxDone.jsp"); else { response.sendRedirect(response.encodeRedirectURL(this.loginUrl + ...
使用session页面限制访问;使用application显示在线人名字列表; 使用servlet+ajax实现无刷新发言与更新实时聊天记录以及注册时文本框失去焦点AJAX验证用户名是否已重复; 系统支持双人聊天与群聊,群聊登陆界面为...
使用jQuery和Bootsrap完成网站前端JS脚本和样式处理; 前后端的数据请求交互通过Ajax完成; 引入了Moment.js格式化前端页面显示时间; 2、项目后端搭建: 使用NodeJs的express框架完成电影网站后端搭建; 使用mongodb...
该购物车全程使用三层架构,使用Ajax弹出框验证用户登录,使用Session保存hashtable对象的方式保存每次用购买的商品ID和商品数量,以减少和数据库的交互次数,功能有登陆,购物,查看订单,生成订单....,,
现在Ajax在Web项目中应用广泛,几乎可以说无处不在,这就带来另外一个问题:当Ajax请求遇到Session超时,应该怎么办? 显而易见,传统的页面跳转在此已经不适用,因为Ajax请求是XMLHTTPRequest对象发起的而不
在后台应用程序中设置:Session.Timeout = 1; 注意:1、此方法可以设置在一个公共的页面中,然后直接调用即可。 2、时间是以分钟为单位的 方法二: 在Web.config中设置: 在<system></system>中写入...
包含了http的集群环境,https的集群环境,同时考虑到集群环境的session问题,使用了tomcat+memcached实现tomcat集群环境共享。整个环境解压既可以使用,证书如果需要修改,直接将证书放在nginx的config目录,然后...
MyEclipse+mysql+Ajax工具,解决用户同一时段不能重复登录,第二次登录将会挤掉第一次登录用户,弹出消息框(你已在其他地方登录,被迫下线),我也是借鉴其他大师 然后自己整理的。基本逻辑是:用户登录时候检测...
tomcat+nginx+memcache+session 所需jar包,包括memcache等安装包