aspose file tools*
The moose likes Servlets and the fly likes How to show progress? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to show progress?" Watch "How to show progress?" New topic
Author

How to show progress?

Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 740
when this code works nothing shows the progress and page remains as it is for a long time. I have given the form target a mini frame right bottom of the page to output when finish. There is no error in the code.

Can you please let me know how can I show the progress of the sent mails as this code is sending more than 20K emails

I want to show the number of emails sent

thanks & best regards


[ October 18, 2008: Message edited by: Farakh khan ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42635
    
  65
What kind of client is this - web app? Desktop app? Something else?


Ping & DNS - my free Android networking tools app
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 740
Originally posted by Ulf Dittmer:
What kind of client is this - web app? Desktop app? Something else?


webapp (Java Servlet)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

Have you considered an Ajax solution?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 740
Originally posted by Bear Bibeault:
Have you considered an Ajax solution?


I want solution in Java as well in the way that it should show the progress of sending mails that how many emails sent and this figure should change with each loop but when it show the next figure previous should be deleted

Thanks & regards
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42635
    
  65
Being a web app, it won't be completely in Java - some client-side code (or at least HTML) will be involved. AJAX can help avoid having to reload the web page that shows the current status. It's at least something to consider.

You'll also need a servlet that can return the current status to the client. So you need to think about how to keep the status in a place where that servlet can access it, maybe as an attribute in the web app context.
[ October 18, 2008: Message edited by: Ulf Dittmer ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

For a pure Servlet/JSP solution, you'd need to refresh the page continuously, updating the progress display each time.

The processing would need to be spun off into its own thread (or performed in a separate daemon program) so that the Servlet thread could continue and return information while the processing goes on.
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 740
Originally posted by Bear Bibeault:
The processing would need to be spun off into its own thread (or performed in a separate daemon program) so that the Servlet thread could continue and return information while the processing goes on.


Can you please elaborate more the above point? Please in easy language as my English is weak

Thanks & regards
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

In order for the long process to be independent from the display (and therefor not block the response), it either must be in its own thread, or in another program completely.

Personally, I'd not use a progress bar at all. I'd just let the long process proceed in the background and have a place where the user can go in order to check the status. That way, they are not just sitting there watching a progress bar complete, but can be doing other things.

Ben Souther has a "Long Running Process" example on this page.
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 740
>>>>>and have a place where the user can go in order to check the status

That's I need

Regards
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14351
    
  22

Seeing this question and your other question, I think that you don't understand how the HTTP request-response cycle works with regard to servlets.

It works like this:
  • User enters an URL in the browser. Browser sends an HTTP request to the server.
  • The app server (Tomcat for example) calls your servlet to handle the request.
  • The doGet() method in your servlet generates an HTML page and returns.
  • The app server sends the generated page back to the browser in an HTTP response.
  • The browser on the user's computer displays the HTML page.

  • Note that generating the page by the servlet and rendering the page in the browser are two separate steps, that happen one after the other. So, the browser is not rendering the page while the code in your servlet runs - that happens after the servlet has finished.

    If your servlet sends e-mails, then the resulting HTML page which shows the status is not sent back before the servlet is done with all the e-mails. You can't show the progress by making the servlet print something to the output, because the output won't be sent back to the browser before the servlet is done.

    One way to show a progress bar is to program it in JavaScript (running in the browser), with AJAX (where the JavaScript is sending to and receiving requests from the server to check the status).
    [ October 18, 2008: Message edited by: Jesper Young ]

    Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
    Pat Farrell
    Rancher

    Joined: Aug 11, 2007
    Posts: 4659
        
        5

    Ignoring for a minute the topic of how you display that progress bar, think about this first:

    How do you know where you are in the progress?

    A lot of Microsoft packages show a nice progress bar that when it gets to the end, just goes back to the beginning. Sometimes many times.

    Do you want a progress as in real percent complete? or just some eyecandy to distract the user? The latter is a lot easier to do.

    With many actions on the server, you can't tell before hand how long it will take, so you can't provide any real progress information.

    Do you show the percentage of expected time to happen, based on an empty system? what happens when the system is slashdotted or on the front page of digg?
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: How to show progress?