0

I have a application that invokes a servlet through the URL

> "http://server:port/context-root/myservlet"

The servlet then calls the Java Class which returns the query result back to servlet.The servlet then renders the data to the user through a JSP page(response.redirect)

Now it hapens so, when all this happens Page Cannot be displayed is rendered to the useruntil the JSP page is ready to show the data.

How can I show a loading gif or a messgae as soon as the servlet is invoked until the JSP page is loaded with all the required data:

NOTE: As mentioned above, I am first calling the servlet, then Java Class, then JSP.

Sankalp
  • 173
  • 2
  • 9
  • 25
  • 2
    read ajax and jQuery- doesnt matter what the server-side flow does – user1428716 Feb 17 '13 at 07:28
  • refer : http://stackoverflow.com/questions/6134110/how-to-display-ajax-loading-image – user1428716 Feb 17 '13 at 07:29
  • But where and how do I write ajax query in a servlet.I am using doGET() method of servlet.I am a little beginner so please help, I have read other post regarding this.There people first calls JSP or HTML and then servlet, but here I am calling sevlet first – Sankalp Feb 17 '13 at 07:32

1 Answers1

0

@Sankalp - The invoking application (HTML page ) is solely responsible for making an AJAX Call to your servlet. If you dont have control over the invoking application here is a little trick you can do - Ask the invoking application to re-direct to an html file say an index.html file of your application . In the index.html file , export jQuery javascript library and make appropriate ajax call , show a loading image , and upon success you may re-direct the page to desired jsp. There is a lot of work to be done here.

Question : Does the invoking application pass you any parameters ? Does it POST data to you ? Does your application open in an IFRAME of the invoking application or its a pure re-direct ?

All these answers , would help you decide your next course of action. There are lots of post on AJAX calls and showing images on stack overflow but that does not solve your essential problem . You have to decide on the flow and where to put the AJAX code. The AJAX part would be the easiest one. :) ----- Editing after the last comment

Visit : jQuery

In your HTML

  <html>
    <head>
     <script src="jquery.min.js"></script> <!-- where you keep your resource file -->
      <script language="javascript" type="text/javascript">
       $(document).ready(function() { //This call will be made when DOM 
            //hierarchy has been fully constructed
            // Handler for .ready() called.
            //Make AJAX Call here so that this simple HTML page 
            ///directly calls the AJAX
            // and decide the future action based on AJAX success / failure
       }); 
      </script>
    </head>
    <body>
    </body>
  </html>
user1428716
  • 2,078
  • 2
  • 18
  • 37
  • I have no control over the invoking application.All I do is to put the URL in the application.So by default onlydoGET will be called.I am also passing parameters.(One question though it is unreleated: Can I configure my servlet such that what ever request it recives like GET , it alwasy execute the doPost metod). Beside when you said that lot of work will be done hear, my heart shattered, as I dont know AJAX and I have few days to make every thing working.Certain question that came up to my mind instantly and kileed me where [Read Comment Below] – Sankalp Feb 17 '13 at 08:51
  • [Continued from above comment] 1. How would HTML invoke servlet automatically(I have always called a servlet through form action or request dispatecher. 2. Where would I find these AJAX libraries and where do i put my AJAZ code in HML page(Body, HEAD??) 3. If I have all logics in doPOST() how would I invoke the doGET from HTML(By default it calls GET Though my heart is shattered, but You have still given me some hope. Kindly advice – Sankalp Feb 17 '13 at 08:52
  • OK I have resolved this.I have made a JSP page that retreives parameter from URL and automatically submits the form toa servlet. Now my question Where do I put this ajax code.What libraries do i need to include.Thanks in advance – Sankalp Feb 17 '13 at 10:01
  • Thanks a lot...but I have followed an alternative which is working....tell me If i have wrong..As per you I send a request to a HTML/JSP page(I have used JSP)..I have placed a simple image loading.gif in the body section.The JSP extracts all the parameters from URL and autosubmit the form to the servlet...The loading.gif remains on the screen until the servlet finesh fetching all the data and calls another JSP page where the result is shown.....SO for me this works like AJAX, but ofcouse without AJAX....Can you pleae comment on my approach...Wahts are the draback if any.. – Sankalp Feb 18 '13 at 11:30