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

狂风中的少年 提交于 2019-12-12 18:09:51

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!