Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet reporting progress

 
Yile Ku
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65227
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Yile Ku
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65227
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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-
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic