• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 500
  • Last Modified:

How to use loading image in Java/j2ee application


Hi,

How to use loading image in Java/j2ee application .  in my application i will submit the for m then i t will go to DB and do some transcation and update or insert the data . it take 10 to 30 sec ...

that time i want ask user to wait the process to complate . so i plan to display loading image how can i implement that !!
0
Sathish David  Kumar N
Asked:
Sathish David  Kumar N
  • 6
  • 4
  • 3
  • +1
3 Solutions
 
colr__Commented:
You wouldnt do this with java, you'd be best doing it with JavaScript. When the user clicks the submit button, use Javascript to show a loading image via the onclick handler. This will then disappear when the page finishes processing and goes to the next page (the processing page).
0
 
cmalakarCommented:
Better do with AJAX.

On submit of form, show a progress image on the page, Send an ajax request with form details.
Once the ajax request is completed, just forward to the success/failure page based on the ajax request/response result.
0
 
rrzCommented:
Here is a JSP that demonstrates what you want to do. You can do the same thing in a Servlet.
<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.
I am not sure how much padding is necessary. This works in IE 8.
<%
  out.print("<img src='yourLoading.gif' />");
  out.flush();
  for(int x = 0; x < 3; x++){
                             Thread.sleep(3000);  //mock processing
                             out.print("<br/>Processing.");
                             out.flush();
  }
%>
<br/>Finished processing.
</body>
</html>

Open in new window

0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Sathish David Kumar NArchitectAuthor Commented:
@colr__: @ cmalakar:

I put the image in div tag in one jsp i include that jsp in all pages ...  but the gif file is not working , if i put the image in same page then that gif file is working fine ... why ? i am understand ...
0
 
Sathish David Kumar NArchitectAuthor Commented:
@rrz@871311:

Most of my user are working in IE^ only . so i test the code but .. its not working ...
0
 
rrzCommented:
>its not working ...
What happens ?
I tested in IE8. It works for me.
Did you just copy and paste my code ? ( just change the image file name and put the file along side the JSP)
0
 
colr__Commented:
Personally I think a javascript approach is better for this type of thing:

<img src='yourLoading.gif' style="display:none;" id='theImg' />

<form onsubmit="document.getElementById('theImg').style.display='block';">
...
</form>

Open in new window


The advantage of this is that you dont have to wait for thre posted form to begin to return - the loading image will display as soon as the user hits the submit button. By doing it in java you are also moving display-related stuff into your java code, which is not a good design.
0
 
rrzCommented:
colr makes some good points but I think it depends on the application.  It seems to me that server should be in control.
What if some of the form fields are invalid ?
0
 
cmalakarCommented:
>> I put the image in div tag in one jsp i include that jsp in all pages ...  but the gif file is not working

Can you show the code.. ?
0
 
Sathish David Kumar NArchitectAuthor Commented:
This code in one jsp

<div id="imageDiv" >
                         
                         <img alt="processing...... " src="/x/img/cri4.gif" >  <b>Please Wait... </b>
                      </div>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link type="text/css" href="/xforcesTool/css/jquery-ui-1.8.12.custom.css" rel="stylesheet" />      
<script type="text/javascript" src="/xforcesTool/js/jquery-1.5.1.min.js"></script>
<script type="text/javascript" src="/xforcesTool/js/jquery-ui-1.8.12.custom.min.js"></script>

<script type="text/javascript">


$(document).ready(function(){
       
      $("div#imageDiv").hide();
          
      $("a").click(function(){      $("div#imageDiv").show(); });
            });



</script>

0
 
Sathish David Kumar NArchitectAuthor Commented:
that above jsp inculed in my other jsp

when cilck button i call some java script method

in that method i write
$("div#imageDiv").show();

that image display but its not rotate (gif)
0
 
Sathish David Kumar NArchitectAuthor Commented:
any input ??
0
 
colr__Commented:
I take it the gif rotates when viewed normally? Is the animation set to rotate indefinetly, or would it stop rotating after a specified time?

The reason I ask is that although the image is not visible as you've used hide() - the image is still there and rotating in the background. So if the gif is set to animate for only a set period of time, that time may have elapsed by the time you're calling show()
0
 
cmalakarCommented:
>>$("div#imageDiv").show();

When is this being executed.. after submitting the form or before ?

You can comment out the form submission code and see, if the image really rotates or not, with the above code.
0
 
Sathish David Kumar NArchitectAuthor Commented:
if i put in same page means it will rotates put i inculde the image it wont rotate.
0
 
cmalakarCommented:
>>if i put in same page means it will rotates put i inculde the image it wont rotate.

including one jsp in other is something that gets executed at server. Client is not aware of that includes.

All that you should see is

   1) In both include and don't include cases,  does the images urls that you get to the client are same ?

   2)  When you include another jsp, On clicking the submit button if you just show the image without form submission , does the image really rotates or not ?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 6
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now