在JSF中防止长时间处理期间的会话超时 [英] Preventing session timeout during long processing time in JSF

查看:155
本文介绍了在JSF中防止长时间处理期间的会话超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究JSF应用程序.在一个地方,我必须在托管bean中调用一个动作.该操作实际上处理了数百条记录,并且会话在处理完成之前超时.

I've been working on an JSF application. At one place, I've to call an action in managed bean. The action actually process hundreds of records and the session timesout before the processing is finished.

尽管所有记录均已成功处理,但会话已过期,并且用户已被发送到登录页面.

Though all the records are processed successfully, the session expires and the user is sent to login page.

我尝试添加

session.setMaxInactiveInterval(0);

session.setMaxInactiveInterval(0);

在处理记录之前无效

在此过程中如何防止会话超时.

How to prevent the session time out during such process.

推荐答案

只要最终用户在webbrowser中打开页面,就引入ajaxical民意调查以保持会话有效.这是在 jQuery 的帮助下的启动示例.

Introduce ajaxical polls to keep the session alive as long as enduser has the page open in webbrowser. Here's a kickoff example with a little help of jQuery.

<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
    $(document).ready(function() {
        setInterval(function() {
            $.get('poll');
        }, ${(pageContext.session.maxInactiveInterval - 10) * 1000});
    });
</script>

此处 ${pageContext.session.maxInactiveInterval} 返回会话尚未存在的剩余秒数(已减去10秒-只是为了按时轮询-并转换为毫秒,以便适合

Here ${pageContext.session.maxInactiveInterval} returns the remnant of seconds the session has yet to live (and is been deducted with 10 seconds -just to be on time with poll- and converted to milliseconds so that it suits what setInterval() expects).

$.get('poll') 应该调用一个servlet,该servlet映射到的url-pattern /poll,并且基本上在doGet()方法中包含以下行.

The $.get('poll') should call a servlet which is mapped on an url-pattern of /poll and contains basically the following line in the doGet() method.

request.getSession(); // Keep session alive.

就是这样.

这篇关于在JSF中防止长时间处理期间的会话超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆