JSP Progress Bar

Is there a quite easy way to implement progress bars in JSP. Basically I have a JSP page that goes to a servlet that calls up a method, now this process is going to run for a long time and I want to indicate the status of the progress just like the progress bar that shows up in the eclipse taskbar when we execute any java program.

I have found a nice tutorial here http://onjava.com/pub/a/onjava/2003/06/11/jsp_progressbars.html but it seems little outdated.

Are there any new and easy ways to implement this?


Determining the progress of a particular task is a surprisingly complicated thing once you get into the details. How do you determine for example that you are 50% done? And what happens if the last 10% of your task takes 1/2 the total time?

Usually for a web app, if you do want progress bars, then going the AJAX route is best, as some of the posters mentioned above. I find, however, that on the web, it is suitable to indicate to the user the something is happening. Just have a spinner of some sort made visible when the page is submitted, and then hidden again when it is rendered ( see here ). This is very easy to do, causes no additional performance hit, and is indicative of some sort of progress


There is a lot of solutions for example jQuery.

You can use Jquery with Ajax to update progress bar:

http://jqueryui.com/demos/progressbar/


In my opinion, when you call your jsp, it should return to the user immediately but also indicate that some complex task is being dealt with in the background (with a loading spinner, for example). If you want to know the task's progress, you should use either Ajax polling, or Comet push in order to retrieve it from your server. For just getting and displaying progress, I think Ajax is sufficient and Comet might be a bit of an overkill. Here is more on the Ajax approach:

http://en.wikipedia.org/wiki/Ajax_(programming)

More on your question, a servlet(and also a jsp) work according to the HTTP protocol, which is based on the request->response model. In today's world, there are rarely sites where you go to a jsp to do a complex task and then you have to sit around doing nothing while your request is complete. You might want to give your user the freedom to still interact with your web-application/website while his request is being dealt with in the background.

链接地址: http://www.djcxy.com/p/52472.html

上一篇: Python中意外的相对导入行为

下一篇: JSP进度条