你可以使用如下:我在jsp页面中使用它,比如heade.jsp。它对我来说工作正常。我正在使用弹簧,jsp和jquery。
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>