473,326 Members | 2,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

JSP processing progress indication

dzenanz
45
I have JSP web-form which uploads a file. In java code, I have a statement like this:

Expand|Select|Wrap|Line Numbers
  1. for all lines in txt file uploaded
  2.   call DB stored procedure
As this web interface should be used over a network, and not internet, file upload ends pretty quickly, but DB loop lasts for minutes (if file is longer).

How can I give indication of loop's progress to the user? Percentage or progress bar would be ideal, printing a dot for each line processed would be acceptable.

Any combination of technologies are in play: javascript, multithreading, (I allready use iframe on the form page), etc...

Also, when explaining, you should have in mind I am new to java platform (I have more experience with ASP.net).
Apr 9 '08 #1
5 3176
r035198x
13,262 8TB
I have JSP web-form which uploads a file. In java code, I have a statement like this:

Expand|Select|Wrap|Line Numbers
  1. for all lines in txt file uploaded
  2.   call DB stored procedure
As this web interface should be used over a network, and not internet, file upload ends pretty quickly, but DB loop lasts for minutes (if file is longer).

How can I give indication of loop's progress to the user? Percentage or progress bar would be ideal, printing a dot for each line processed would be acceptable.

Any combination of technologies are in play: javascript, multithreading, (I allready use iframe on the form page), etc...

Also, when explaining, you should have in mind I am new to java platform (I have more experience with ASP.net).
Have you tried something like out.print as the last statement of you for loop?
Apr 9 '08 #2
dzenanz
45
Have you tried something like out.print as the last statement of you for loop?
No, but I assume that I would also have to flush the stream, and I am not sure that browser would display data as soon as it arrives.

I wanted to check for ideas on this forum first.

If println works, what do you think, would something like this work:

Expand|Select|Wrap|Line Numbers
  1. output header:
  2. ...
  3. <input type="text" name="perc" id="perc" value="0%" />
  4. <script language="javascript">
  5. label=document.getElementById("perc");
and then in loop:
Expand|Select|Wrap|Line Numbers
  1. {
  2. ...
  3. out.println("label.value='"+i+"%';");
  4. out.flush();
  5. }
Apr 9 '08 #3
r035198x
13,262 8TB
No, but I assume that I would also have to flush the stream, and I am not sure that browser would display data as soon as it arrives.

I wanted to check for ideas on this forum first.

If println works, what do you think, would something like this work:

Expand|Select|Wrap|Line Numbers
  1. output header:
  2. ...
  3. <input type="text" name="perc" id="perc" value="0%" />
  4. <script language="javascript">
  5. label=document.getElementById("perc");
and then in loop:
Expand|Select|Wrap|Line Numbers
  1. {
  2. ...
  3. out.println("label.value='"+i+"%';");
  4. out.flush();
  5. }
Perhaps a bit more info on your problem ...
That for-loop is executed on the server and is run once before the page is rendered right? If you want some interactive behaviour then you might have to try some AJAX stuff.
Apr 9 '08 #4
dzenanz
45
What AJAX frameworks for Java are there? I mean, for this concrete problem, is it easier to integrate some asynchronous calls or add iframe to resulting page that will be refreshed by javascript (by polling status on the request every few seconds or so)?
Apr 9 '08 #5
dzenanz
45
I solved it like this:
  • Add text element in a div
  • Hide div in body onload
  • For each progress update call update_progress function ("up") wrapped inside <script> tags. If all calls are made inside one script tag, they are executed when browser encounters closing script tag, which is in my case - when the processing ends
example of output:
[HTML]<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>page title</title>
</head>
<body onload="document.getElementById('progress').style. display='none'">

<div id="progress"><br />Progress: <input type="text" id="progressText" value="0%" readonly="readonly">
</div>

<script type="text/javascript">
var pp = document.getElementById("progressText");
function up(p)
{
pp.value=p.toString(10)+'%';
}
</script>

<script type="text/javascript">
up(1);
</script>
<script type="text/javascript">
up(2);
</script>
<script type="text/javascript">
up(3);
</script>
...
<script type="text/javascript">
up(97);
</script>
<script type="text/javascript">
up(98);
</script>
<script type="text/javascript">
up(99);
</script>
<script type="text/javascript">
up(100);
</script>
<br />
<br /><h2>Success</h2><br />
-rest of page-
</body>
</html>[/HTML]of course[HTML]<script type="text/javascript">
up(2);
</script>[/HTML]are generated in a for loop with this:
Expand|Select|Wrap|Line Numbers
  1. if (percentage.intValue() > oldPrecentage) {
  2.     oldPrecentage = percentage.intValue();
  3.     out.printf(progressString, new Object[]{percentage});
  4.     out.flush();
  5. }
  6.  
with
Expand|Select|Wrap|Line Numbers
  1. progressString="<script type=\"text/javascript\">\nup(%d);\n</script>\n";
Dženan
Apr 10 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: Paul | last post by:
i have been working with vb6 for a while but never had the pleasure of using progress bars. That is until now, one of the programs i have written has just been modified so that large csv files of...
4
by: Nadim Attari | last post by:
Hello, If i upload a file thru' the POST method, can i know the num of bytes uploaded at time x ??? All i want is to make an "upload progress bar" Is this possible ? Any links, articles,...
5
by: Søren Reinke | last post by:
Hi there I am working on a program where the user should be able to import some CSV files. With my set of test data, it takes about 2 minutes to import, while it is importing the program sort...
8
by: Raed Sawalha | last post by:
I have form with progress bar ,when application begin processing and progress bar moving if I minimized the form and try to restore it ,it is not showing until the processing completed ,how can I...
0
by: King Tut | last post by:
I would like to display a progress bar (or some progress indication) when the user hits a submit button until the request is completed and is loaded.... Something that works like Flash, when you...
6
by: Shawn Regan | last post by:
Hello, What is the best practice to show a window/form of some animation while processing is going on in the back ground. I want the user to see something while some processing is taking...
6
by: Botak | last post by:
I am able to simulate and run the "thread" as adviced earlier from my previous post. Thanks for the tips. Now I am stucked at how to get the progress status from the thread. I have a main form...
11
by: processoriented | last post by:
Hi, I'm something of a noob at this, but here it is... I have an app that fills a dataset from a SQL database, and then writes the dataset to an xml file. Everything is a SELECT query... I am...
2
by: mcw.willart | last post by:
Hi, I use a backgroundworker to get the total size of a homeshare (as it is a bit time-consuming). Wat i would like to do, is show the progress, but at start i don't know how much files/folders...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.