File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple responses to one request

 
Daesung Park
Ranch Hand
Posts: 68
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I know, Ajax using XHR can handle only one response per one request. It seems to be limitation of web applications that uses Ajax.
For example, web page displays a table by querying to a server, but it takes several minutes for server to retrieve all data. So, I want to make server to responses currently retrieved data every 10 second and client handles every response. Is it possible or is there any workaround?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is typically done by having the client poll the server every n seconds to see if the job is done.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may also want to explore the comet architecture.

I don't know how widely used it is or what kind of browser support there is for it but it's there.

I, personally, would go with polling AJAX calls.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Daesung Park:
As far as I know, Ajax using XHR can handle only one response per one request. It seems to be limitation of web applications that uses Ajax.

This is a "limitation" of HTTP, not Ajax. Ajax and XHR can't make HTTP do anything that it was not designed to do.
[ January 16, 2008: Message edited by: Bear Bibeault ]
 
Daesung Park
Ranch Hand
Posts: 68
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:
This is typically done by having the client poll the server every n seconds to see if the job is done.


Thanks for your reply.
I used client polling, but not satisfied with it. My dissatisfaction may comes from wrong design of server side. I can design 2 types of server-side as below

(a) In server side, jsp retrieves data and writes currently retrieved records to a output file which is the target of client's query.
: It is simple, but on each polling, reponse text is not delta but accumulative records.

(b) In server side, jsp is the target of client. Query string to the jsp should include client ID and query sequence number. If sequence num is 0, jsp starts retrieving data and writes them to a output file(Each ID has own output file). If it is over 0, jsp reads some records (stored in output file) corresponding to ID/sequence number and returns the records.

I am using design similar to (a).
Is (b) reasonable and the way typically used?
Could you share nice ideas on this issue?
[ January 17, 2008: Message edited by: Daesung Park ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote a demo app that shows one way of doing this.
http://simple.souther.us/not-so-simple.html
Look for long running process.

It was kept as simple as possible so it refreshes the whole page instead of using AJAX but the same principals apply. It also uses a session scoped object to store the state of the long running job.
In the real world, I store the state in a database table so the user doesn't need to keep a session alive in order to keep in touch with the job.

In a nutshell, I kick off the the job in a new thread and immediately return a status pages that refreshes every n seconds. With each refresh, it checks for a 'Done' status. If not done, then I return the refreshing status page. If done then I return the resulting page, report, file, whatever...

It would be very easy to adapt this model to use AJAX and a database.
Another nice touch would be to have the app email the user once the job is complete so she can do other things while waiting for the job to finish.

Also, in the real world, (and I think this might answer your 'B' scenerio),
the refreshing page has a list of all jobs -- finished and unfinished -- by this user so she has the option of viewing previous reports generated with this component.

Does this help?
 
Daesung Park
Ranch Hand
Posts: 68
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ben for your kind answers.
 
SaurabhSri Sri
Ranch Hand
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Daesung,

Did you implemented any solution. I am also looking for the same.
I want to make server to responses currently retrieved data every 10 second and client handles every response.

Thanks in advance.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic