问题
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.
回答1:
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/
来源:https://stackoverflow.com/questions/7992153/ajax-long-polling-in-java-spring-mvc-session-scope-issue