• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Ajax instead of refreshing page

 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to use Ajax instead of meta refresh to display loading indicator.

the present code is

loading.getURL()will give the servlet url. in the servlet i am just checking if the text loaded or not. if yes then go to text.jsp and display text otherwise go to loading.jsp and display loading indicator

so now how can i change the loading.jsp to use ajax instead of refreshing the page.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It sounds like you are loading completely different pages depending upon a server-side decision. Is that what you are doing? If not, please explain in another way.
 
vijaya bacina
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes that is true. if the text is still loading(i am checking this in servlet) then forward to loading.jsp where loading indicator will display, otherwise go to text.jsp where text displays.
overall i am showing a loading indicator until the text loads.
 
vijaya bacina
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it not possible with Ajax???
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using Ajax would be a severe over-complication. Deciding which page to show based upon server-side criteria is a decision best made on the server and at an early stage in the request, either in the servlet controller or a servlet filter.
 
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why not take them to one page, and while the page is loading have a loading animation. When the page is done loading, hide or remove the animation div and show the content... No need for two separate pages.
 
vijaya bacina
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To get the text.jsp(where document be shown), in the background (servlet/filter) there are so many places which will stop the process in order to render the text(like to display pdf blobs etc). stop in the sense thread.wait(). so when this is executing the screen just sits blank.
that is the reason why i am redirecting it to different jsp(loading.jsp) and in the background let the process complete. once the process completes the servlet/filter can not wait since the process was already done.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well that's a bit more complicated than indicated in your initial post. Why are things waiting? It's very unusual.

You might want to take a step back and give us the big picture of what you are trying to accomplish. I really don't have a clue at this point.
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is an article that I bookmarked that looked interesting:
http://blogs.crsw.com/mark/articles/642.aspx

I have not actually given it a try and there seems to be quite a bit of JavaScript code involved. Check out the "BusyBox Demo" link.

- Brent
 
vijaya bacina
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is my Documentservlet
1)getDocument();
the getDocument() will start multiple threads like getNextandPreviousContents(), getKeywordNavigation(), validateLinksInText(), etc
2)waitForAllThreads() here is where my process just stops and waits and the screen stays blank
3) add document to user browsing history
4) some other tasks that really depend on document to load completely
5) then only show jsp / forward to Text.jsp

what i changed now in DocumentServlet is
1)getDocument()
2) if(doc is not yet loaded)
forwardTo loadingServlet.java (see below)
3) add document to user browsing history
4) some other tasks that really depend on document to load completely
5) then only show jsp / forward to Text.jsp


loading.jsp
will just refresh(META TAG) every 3 secs calling loadingservlet.java and displays loading image

loadingservlet will just check
if document loading done go to DocumentServlet(this servlet will call getDocument() but will not start threads again, just gets document)
else go back to loading.jsp.

question was "is there any way that i can replace the refresh(in loading.jsp every 3 secs which is i know very annoying) to use ajax?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But you haven;t answered my question as to why:

will start multiple threads



Why does this have to be multi-threaded with all the waiting?
 
vijaya bacina
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
since each task will take much time, i am using multithreading concept so that they can be done simultaneosly(they are independent tasks) pretty quick
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might want to check out this thread in the Servlets forum:

https://coderanch.com/t/365465/Servlets/java/Long-running-task-servlet

for better ideas on handling long-running processes.

Particularly Ben Souther's post:

On my site, I have a simple demo app that does something similar.
http://simple.souther.us/not-so-simple.html

Look for LongRunningProcess.
It might be enough to get you going in the right direction.

 
vijaya bacina
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Brent, The article is very good.
Thanks Bear i will take a look into the longrunningprocess
reply
    Bookmark Topic Watch Topic
  • New Topic