Session Timeout w/Ajax Polling in Spring Web Application
Asked Answered
O

2

6

I'm developing a Spring 3.0 based web application that requires all users to log in to view data. Once logged in, certain parts of the screen use an AJAX polling mechanism to update screen content in the background. Currently, our session will not time out because each ajax request to the server updates the timeout of the web application, and the session never times out.

What I need to is modify the application such that when a user is logged in, the controller will respond to the poll with data, but not update the session timeout so the session times out at its scheduled time. If the user does not have an active session, the controller doesn't return anything.

How would I go about doing this?

Octosyllable answered 11/3, 2011 at 18:49 Comment(1)
Can you let me know how did you handle this?Brenna
A
0

You're going to have to muck around in the internals of your servlet container.

Here's what I would do

  • Search google for "xhr XmlHttpRequest servlet container session access" and see if anything interesting comes up (I'm too lazy to do this right now)
  • With whatever servlet entine you're using, pull the code down locally and have a look at the session implementation. Specifically, you want to figure out what is setting the value that is returned by javax.servlet.http.HttpSession.getLastAccessedTime. When you find this, work backwards to find out how you can customize this. I'm pretty sure you could do this with Tomcat by extending one of it's internal classes and using your custom class by setting it in your XML config file.
Adipocere answered 12/3, 2011 at 4:49 Comment(0)
H
0

How about using using <%@ page session="false" %> for pages that deliver ajax data. Since these pages will not be tied to session, session timeout might not be updated.

Homovec answered 5/5, 2011 at 21:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.