Solved

JSP, show a loading spinner

Posted on 2010-11-19
11
2,071 Views
Last Modified: 2012-05-10
I have a third party jsp page we are using in an application.  The page has a lot of internal logic and lengthy database queries and page loads are typically 10 - 20 seconds.    I am new to jsp, it is possible to display a loading message or ajax spinner while the page is loading?  I have done this before using .net pages, but I am not sure how to make this work with jsp.

Any help would be greatly appreciated.
0
Comment
Question by:shanemay
  • 6
  • 5
11 Comments
 
LVL 27

Accepted Solution

by:
rrz earned 500 total points
ID: 34175534
>page loads are typically 10 - 20 seconds.  
Do you to say that nothing shows up in the browser until then ?
Please try this demo code.
<html>
<body>
Some text here is necessary here for the IE browser to start displaying. 
Otherwise it will wait until it receives enough of a response to begin displaying anything.
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz I am sure how much padding is necessary. But this works for me.
<%
  out.print("<br/>Starting processing now. <br/>");
  out.flush();
  for(int x = 0; x < 3; x++){
                             Thread.sleep(3000);  //mock processing
                             out.print("Record for cust-id" + x + " submitted and mail sent successfully.<br/>");
                             out.flush();
  }
%>
</body>
</html>

Open in new window

0
 

Author Comment

by:shanemay
ID: 34175559
I will give your code a shot, but yes, nothing shows in the browser until then, the page does alot of processing and at the end dumps text onto the page.
0
 

Author Comment

by:shanemay
ID: 34175607
Same result, the page loads slowly, but nothing shows while the page is processing.  Even a message saying loading would be better than a blank screen.  
0
 
LVL 27

Expert Comment

by:rrz
ID: 34175683
Did you try my demo code ?
out.flush() is the key. It will send whatever is in buffer at that time. But as I explained in demo it needs some output at begining to get the ball rolling( especially in IE).
0
 
LVL 27

Expert Comment

by:rrz
ID: 34175723
Please show some pseudo code that describes what you are doing. Give us more details.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:shanemay
ID: 34175791
I did try the code listed above ( page was blank during processing ).  As for pseudo code - The page creates a connection to the database, runs five queries, processes the results into a set of links, then displays the links for the user with some standard text as a header and footer which is also pulled from the database.  Nothing displays on the page until all the processing is complete which can take some time.    Also, the page is being displayed in an iframe (if that matters).

Thank you for your help.
0
 
LVL 27

Expert Comment

by:rrz
ID: 34176000
I did try the code listed above ( page was blank during processing ).  
Which browser are you using ?
When I run it, it display the first couple of sentences right away. After 3 seconds it displays
Record for cust-id0 submitted and mail sent successfully.
then after 3 seconds it displays
Record for cust-id1 submitted and mail sent successfully.
and so on.    

As for your code, why not get the header and send that using out.flush() It needs to big enough for IE to react.
After that, can you get the links one at a time and send them individually with out.flush()  ?

0
 

Author Comment

by:shanemay
ID: 34176053
I am using FireFox 3.6 and IE 8 as testing.  
0
 
LVL 27

Expert Comment

by:rrz
ID: 34176192
I just tested in a iframe in IE 8.   The output is displayed progressively as I posted.
Did you just cut and paste my exact JSP ?  
0
 
LVL 27

Expert Comment

by:rrz
ID: 34176201
You have to name the file  something like test.jsp
0
 

Author Closing Comment

by:shanemay
ID: 34192605
Thank you for your help, sorry for the late response.  That is working now, not sure what I was doing, but it works fine.  
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now