在会话超时之前警告用户 [英] Warn the user before session timeout
问题描述
我有一个在 Spring MVC
, JSP
中实现的Web应用程序。
默认会话超时在 web.xml
中定义为30分钟。
I have a web application implemented in Spring MVC
, JSP
.
Default session timeout is defined in web.xml
is 30 min.
如果用户闲置25分钟,我需要向用户显示弹出窗口您的会话将以5分钟结束,请单击确定继续
。
if user is idle for 25 mins than I need to show a popup to user with message that Your session is going to be end by 5 min, Please click OK to continue
.
我们可以使用 JavaScript
, jquery
来实现这一点或任何其他方法?
Do we can achieve this using JavaScript
, jquery
or any other approach?
请建议。
推荐答案
您可以使用如下:我在jsp页面中使用它,如header.jsp。这对我来说可以。我正在使用spring,jsp和jquery。
You can use like follows: I am using that in a jsp page like header.jsp. It works fine for me. I am using spring, jsp and jquery.
javascript:
javascript:
<code>
<script type="text/javascript">
//var recall = true;
function loadDialog() {
var sessionAlive = ${pageContext.session.maxInactiveInterval};
var notifyBefore = 30; // Give client 15 seconds to choose.
setTimeout(function() {
$(function() {
$( "#dialog" ).dialog({
autoOpen: true,
maxWidth:400,
maxHeight: 200,
width: 400,
height: 200,
modal: true,
open: function(event, ui) {
setTimeout(function(){
$('#dialog').dialog('close');
}, notifyBefore * 1000);
},
buttons: {
"Yes": function() {
$.get("/about", function(data,status){
// alert("Data: " + data + "\nStatus: " + status);
});
$('#dialog').dialog("close");
loadDialog();
},
"No": function() {
$('#dialog').dialog("close");
}
},
close: function() {}
});
});
}, (sessionAlive - notifyBefore) * 1000);
};
loadDialog();
</script>
HTML Div:
<div id="dialog" title="Session Timeout Info" style="display:none">
<p>
Your session will be timeout within 30 seconds. Do you want to continue session?
</p>
</div>
</code>
这篇关于在会话超时之前警告用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!