472,802 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,802 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 3146
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: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.