简体   繁体   中英

Ajax Long Polling in Java, Spring MVC - session scope issue

I am trying to implement a long polling mechanism for auto-updating a grid in a project that uses Spring MVC.

I am sending an Ajax request from the client and on the server side I enter a while loop until data is found then the data is send back as a response.

I need to have another mechanism that stops this operation (that breaks off the loop) when the user changes tab in the application (every tab has a different grid that is auto-updating through long polling. Every tab is handled server-side by a different controller).

What I thought is that I need to have a session scoped variable or bean that changes when the client changes tab and which is accessible from inside the loop so it can break on change. When I tried to use Spring MVC beans scope I noticed that the bean's property that I common in two different sessions (that is HttpSession). I tested this by loging in with a different user from the same machine.

I tried using the but I had the same result.

Any ideas on how to make this work?

Thank you in advance.

Long polling and other async processes are being introduced in Spring MVC 3.2 (currently a milestone release). It might be worth a look rather than trying to implement your own solution.

http://blog.springsource.org/2012/05/13/spring-mvc-3-2-preview-adding-long-polling-to-an-existing-web-application/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM