开发者

J2EE -- Handling HttpSession session timouts while serving flash content

开发者 https://www.devze.com 2022-12-21 01:09 出处:网络
While serving flash based training material users peroidically experience a HttpSession session timeout.Currently the inactivity timeout is set to default (30mins).

While serving flash based training material users peroidically experience a HttpSession session timeout. Currently the inactivity timeout is set to default (30mins).

Questions:

  1. Would it be a good idea to attempt to increase MaxInactiveInterval for any user who is requesting a training flash video to prevent the timeouts?

  2. Would a better approach be to use a servlet lifecycle listener to re-activate the HttpSession if the HttpSession is associated with viewing training content? -- this may allow for more precise control 开发者_JS百科over when the HttpSession object is going to timeout.

  3. Only a small percentage of user's will actually be viewing this material at any one time, is there a performance penalty that should be considered for doing this?


Rather fire ajax polls in the background.

Here's an SSCCE with a little help of jQuery. Just copy'n'paste'n'run it (and change the flash object to suit your actual code).

<!doctype html>
<html lang="en">
    <head>
        <title>SO question 2290101</title>
        <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>
    </head>
    <body>
        <object type="application/x-shockwave-flash" ... >
            ...
        </object>
    </body>
</html>

Here ${pageContext.session.maxInactiveInterval} returns the remnant of seconds the session has yet to live (and is been a tad shortened -just to be in time with poll- and converted to milliseconds so that it suits what setInterval() expects). 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.

That's it.


Is the flash video embedded in an HTML page? If so, perhaps you could have an AJAX call on the page that periodically sends a "heartbeat" to the server to keep the session alive.

0

精彩评论

暂无评论...
验证码 换一张
取 消