0

If I have a servlet which may take several minutes to produce a response, I want to display a single message on the page saying 'Please wait...'

At the moment I have code:

<div id = "subHeader">                    
    <%            
        out.flush();
        for (int i = 0; i < 5; i++){
           if (i == 0) {
               out.print("<h2>Please wait...</h2>");
               out.flush();
           }                        
           Thread.sleep(3000);  
        }
        out.flush();
        out.print("<h2>Results of analysis:</h2>");
    %>            
</div> 

This prints:

<h2>Please wait...</h2> <h2>Results of analysis:</h2>

When the response is pending.

Is it possible to hide the subHeader div so that when the scriptlet has run and the response is made, I only see <h2>Results of analysis:</h2> and the rest of the page?

Mr Morgan
  • 2,215
  • 15
  • 48
  • 78
  • have it hidden by default, and keep polling for existance of particular DOM in javascript, once it is available make it visible – jmj May 19 '15 at 01:26
  • The problem there is that I know nothing of DOM. – Mr Morgan May 19 '15 at 01:27
  • even more reason to learn about it; to do this kind of stuff you pretty much have to know DOM javascript/jquery/Growl notification.Never put this kind of code in JSP file by the way. – Asura May 19 '15 at 01:31
  • True. But I am content to accept a quick and dirty fix here. – Mr Morgan May 19 '15 at 01:32
  • DOM is any element that you can serve to your HTML page once the table rendering is done, and check for its presence to decide weather to show the div now or not – jmj May 19 '15 at 01:33
  • Are you using any libraries at this point like Bootstrap or jQueryUI? If so, they have modals that can be used, and then called to hide via JavaScript. However, since you're waiting (or requesting of some sort) this is being done server-side you'd need some sort of method to PUSH to the client side when ready (btw I'm not a JSP guy). However, if you performed the waiting on the client side in JavaScript, then it's completion could fire an event via ajax, or a timer w/ a callback, etc – JNYRanger May 19 '15 at 02:19

1 Answers1

-2

Using jQuery,

$('#subheader').hide();
Béla
  • 284
  • 1
  • 2
  • 8
  • Thanks but where in the page or scriptlet would this call be made? – Mr Morgan May 19 '15 at 01:58
  • In a script tag after the results of the analysis. – Béla May 19 '15 at 02:02
  • Perhaps a solution like this is better: http://stackoverflow.com/questions/3377468/how-to-show-jquery-message-after-clicking-on-submit-button --> But I am happy to accept a quick and dirty solution based upon this answer for now pending a look at the link above. – Mr Morgan May 19 '15 at 02:31
  • I don't think that's really related. But I agree that this solution is definitely quick and dirty - it's most likely that you should redesign this so that the loading happens asynchronously. – Béla May 19 '15 at 02:41
  • Perhaps not. But as this is not a commercial project, I'm not too concerned. I just wanted something basic working. – Mr Morgan May 19 '15 at 02:45