I want to push the data to the jsp for every 2 seconds, with out client requesting it.
I am using Spring with Hibernate here.
I am displaying google maps marker, and I want to update the marker location for every 2 seconds by getting the data from database, however I have done getting the data from database for every 2 seconds, but I am unable to push that data to this jsp.
@Scheduled(fixedRate = 2000)
public void getData(){
// TODO Auto-generated method stub
DeviceDetails deviceDetails = realTimeDataDAO.getDeviceDetails(deviceId);
System.out.println(deviceDetails);
}
I have to display some data after every 2 seconds. Can anyone tell me how to do that?
any one knows about Comet Ajax Push technology, will it work in this scenario?
Your best bet with Spring is to store the results of the scheduled query into a bean in memory, then have another request-scope bean get that stored result in a method that is web accessible, and return it as text (or JSON). Alternatively you could query the DB everytime an update is requested.
Then, you can make a timed async request from your page (You may want to use YUI Connection Manager for that), read the response and use the panTo method from google.maps.Map to update your map location.
As you can see, the solution is split in a Java and a JavaScript portion.
For the Java side, you must create a controller that performs the query to the database (or better yet, delegates that task to another layer) and returns the results as JSON, you can use http://spring-json.sourceforge.net/ for that. It’s a bit complex in Spring so you might want to instead create a simple servlet that returns the data.
For the Javascript side, once you have a working endpoint that returns the JSON data, using YUI Connection Manager and the google maps api: