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

Servlet reporting progress

Yile Ku
Greenhorn

Joined: Jan 27, 2011
Posts: 13
I have a apache tomcat servlet running on my webserver that does a bunch of work before reporting back to the jsp page at the client. I would like to add a progress bar so the user doesn't think the servlet is dead or not working. Is there a way to add code to my servlet that will report a progress bar to the JSP page displaying in the client browser?

Thanks a bunch.
M-
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61217
    
  66

No. True progress bars are a complex affair with a client side component polling the server (usually via Ajax) which must have a means to obtain a percentage of completion from a long-running process, usually in a separate thread.

Most people simply punt and put up a "working" animation that doesn't show actual progress but gives the user something shiny to look at while the process is running.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Yile Ku
Greenhorn

Joined: Jan 27, 2011
Posts: 13
Thanks for the reply. Okay I will go with the shiny 'im working' page.. how would that be done? I am a bit of a greenhorn to the JSP side.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Brief outline:

(1) The first request starts a Thread which does the long-running process, then it returns a page which says "Working...".

(2) Each subsequent request checks the Thread. If it's still running then it returns "Working...".

(3) If the Thread has finished then the request returns something else, presumably the result of the long-running process.

The "Working..." page can be configured to auto-refresh every X seconds if you like.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61217
    
  66

Or, the page can issue the process as an Ajax request so that it can show the animation while the request is executing.

Note, most of this is JavaScript. JSP isn't going to be of much help except to create the markup.
Yile Ku
Greenhorn

Joined: Jan 27, 2011
Posts: 13
Thanks for the feedback. I am going to ask some newbie questions... so the jsp page is interpreted and executed on the server. The jsp page outputs text that is sent to the client and rendered in the client browser. My jsp page invokes some java servlet classes that execute on the server. So in order to do some kind of status, I need to have some code executing in the client browser querying the servlet as to its status. Also the code executing on the client needs to render the progress bar in the window meant for the output of the JSP page. The the code on the client needs to 'get out of the way' and let the servlet render the computation results. right?

M-
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet reporting progress