File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes using ajax for long running query -- concept questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "using ajax for long running query -- concept questions" Watch "using ajax for long running query -- concept questions" New topic

using ajax for long running query -- concept questions

Marsha Petry

Joined: May 17, 2007
Posts: 1
I have a long-running db query I'd like to do with Ajax and while it's running allow the user to do other things (submit). Once the query is done I never want to query again for that session (since it takes so long)

But I'm clearly missing a big concept... how do I handle a long running XMLHttpRequest query across a form submit? and then *not* do the query ever again?

If I were using JSP alone I'd do something like:
widgets = getWidgetsFromSession()
if widgets == null {
widgets = run long query to get widgets
save widgets in session
display widget list

Then on any page reload the widgets are taken from the session. Happy as a lark except for that darn initial waiting time. So to help with that wait time I want to try ajax:

/*load of page*/
kick off XMLHttpRequest to get widgets
display rest of page which has:
1. an hourglass to tell user widgets are being fetched
2. a form to allow file upload (or could be other action)

Now my confusion:
If I use XMLHttpRequest call a servlet that saves the queried widget list into the user's session, seems like I have to synchronize on the session because the user could have submitted the form, reloaded the page, and kicked off a 2nd XMLHttpRequest, which then calls the same servlet in a 2nd thread (right?). ouch! I don't want to sychronize session during a long query, but if I don't and the page reloads 3 times during the query, there are 3 new requests that may think they have to run the query (again).

If I don't touch the user's session in the servlet, then I've got a widget list in the callback and put in some inner HTML... how would I get that available to the page again after a form submit? Save it in a hidden var?

I'm advanced beginner in javascript and ajax, so clearly there are gaps in
my knowledge. But from what I read, a long-running query is a good use
of ajax.

Have I made any sense? and can you point me in right direction?

Thanks in advance,
I agree. Here's the link:
subject: using ajax for long running query -- concept questions
It's not a secret anymore!