Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

AJAX with servlets

 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have got AJAX to work with servlets, the servlet code is:

and in the jsp page, I basically have...


This works fine, but what I want to do is get servlet to send back some data, then pause for 5 seconds, then send back another piece of data.

Is this possible, thanks for any help.
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would you want to do that? Given that the servlet can only send one response, and that it's going to be buffered in transmission, it sounds rather iffy to me. Why not just have your Ajax code send one request for the first bit, then 5 seconds later send another request for the second bit?

Edit: or you could have the servlet send all of the data, and let your Ajax code pick out the bit which is supposed to be displayed 5 seconds later and display it 5 seconds later.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, basically I wanted to get one client to be able to update a second clients page.
So my idea was for one client to store data as a ServletContextAttribute, then use a listener to 'try to' send data to the other client.

But now that you said that, I could get a client to repeatadly call the server, (perhaps using that javascript setTimeout(...) function), so that it calls servlet, which returns any new Context attributes.

What do you think?

Thanks
 
Arvind Subramanian
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah your idea is correct and i too implemented this in my portal.
just call the ajax function with settimeout javascript fuction. so that the ajax request will be made every given interval and new data will be received from the server.


javascript code
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic