[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to use loading image in Java/j2ee application

Posted on 2011-04-26
16
Medium Priority
?
496 Views
Last Modified: 2012-06-22

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
Comment
  • 6
  • 4
  • 3
  • +1
16 Comments
 
LVL 8

Accepted Solution

by:
colr__ earned 668 total points
ID: 35466900
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
 
LVL 23

Assisted Solution

by:cmalakar
cmalakar earned 668 total points
ID: 35466985
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
 
LVL 28

Assisted Solution

by:rrz
rrz earned 664 total points
ID: 35468010
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 35502917
@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
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 35502923
@rrz@871311:

Most of my user are working in IE^ only . so i test the code but .. its not working ...
0
 
LVL 28

Expert Comment

by:rrz
ID: 35502970
>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
 
LVL 8

Expert Comment

by:colr__
ID: 35504334
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
 
LVL 28

Expert Comment

by:rrz
ID: 35505273
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
 
LVL 23

Expert Comment

by:cmalakar
ID: 35506480
>> 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
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 35697417
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
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 35697438
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
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 35719467
any input ??
0
 
LVL 8

Expert Comment

by:colr__
ID: 35720043
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
 
LVL 23

Expert Comment

by:cmalakar
ID: 35720749
>>$("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
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 35722264
if i put in same page means it will rotates put i inculde the image it wont rotate.
0
 
LVL 23

Expert Comment

by:cmalakar
ID: 35722835
>>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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month20 days, 10 hours left to enroll

868 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