467,166 Members | 1,130 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,166 developers. It's quick & easy.

JSP processing progress indication

dzenanz
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
  • viewed: 2986
Share:
5 Replies
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
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
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
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
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

Post your reply

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

Similar topics

16 posts views Thread by Paul | last post: by
4 posts views Thread by Nadim Attari | last post: by
5 posts views Thread by Søren Reinke | last post: by
8 posts views Thread by Raed Sawalha | last post: by
reply views Thread by King Tut | last post: by
6 posts views Thread by Shawn Regan | last post: by
11 posts views Thread by processoriented | last post: by
2 posts views Thread by mcw.willart@interpolis.nl | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.