session time out in jquery+ajax
5677 단어 session
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);
}
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
redis-rails의 세션 만료 거동을 확인하고 플레이로컬로 사이트에 액세스하는 것으로 3개월의 기한 첨부 세션 데이터가 생성되는 설정을 하고 있다. redis 시작 command DB1 선택(설정에 따라 다름) redis-commands 사이트에 접속, 키 일람을 취...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.