AirFax
asked on
Progress-Bar using JSP/Servlets
Hi, I want to reproduce this using a servlet:
http://www.atgconsulting.com/progressbar.asp
What it does in short is rendering an HTML page sending only a part of it every few seconds. I tried to have the servlet wait for a period of time. I tried to use a timer. And I tried to big loops... Nothing seems to do it for me... Many points for you if you come up with a working example! :o)
http://www.atgconsulting.com/progressbar.asp
What it does in short is rendering an HTML page sending only a part of it every few seconds. I tried to have the servlet wait for a period of time. I tried to use a timer. And I tried to big loops... Nothing seems to do it for me... Many points for you if you come up with a working example! :o)
this is client side HTML/DHTML/JavaScipt effect. all you need to do is to save the .html / JavaScript sources from that site and put it on your server
You could also do a View Source and copy paste the code.
public final class ProgressBar extends Thread {
private Writer writer;
public final void setWriter(Writer writer) {
this.writer = writer;
}
public final void run() {
int progressLevel = 1;
while(progressLevel < 100) {
progressLevel += 1;
writer.print("<script>Prog ressBar.le ngth=\"" + progressLevel + "\"</script>\n");");
}
writer.print("</html>");
}
}
In your servlet, pass your writer to your progressBar.
private Writer writer;
public final void setWriter(Writer writer) {
this.writer = writer;
}
public final void run() {
int progressLevel = 1;
while(progressLevel < 100) {
progressLevel += 1;
writer.print("<script>Prog
}
writer.print("</html>");
}
}
In your servlet, pass your writer to your progressBar.
ASKER
heyhey, this is a server-side trick. I want to provide feedback to the user on something going on in the data-tier. I need the response to last as long as this process.
ASKER
jerelw, you are almost there. I tried that already... The problem with this is the client will only see the end result because of response buffering.
Print and flush everything you want to display until your progress bar begins.
Then print and flush until your progress bar ends.
What you would do is print a <script> that increases the size of the image representing your progress bar everytime.
add this to your run() method:
checkProgress() {
while(notFinished) {
//do stuff
notFinished = doDatabaseStuff();
sleep(5000);
totalTime = System.currentTimeMillis() - startTime;
if(totalTime > DEFAULT_LIMIT) {
out.println("<script>displ ayTimeout( );</script >");
break;
}
}
}
I still don't know how you're going to 'know' what ti indicate in your progress bar if you're simply doing a select.
If you're doing multiple inserts and updates, I guess you could increment a percentage after each transaction and set to 100% after the commit.
Then print and flush until your progress bar ends.
What you would do is print a <script> that increases the size of the image representing your progress bar everytime.
add this to your run() method:
checkProgress() {
while(notFinished) {
//do stuff
notFinished = doDatabaseStuff();
sleep(5000);
totalTime = System.currentTimeMillis()
if(totalTime > DEFAULT_LIMIT) {
out.println("<script>displ
break;
}
}
}
I still don't know how you're going to 'know' what ti indicate in your progress bar if you're simply doing a select.
If you're doing multiple inserts and updates, I guess you could increment a percentage after each transaction and set to 100% after the commit.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.