Progress Monitor for file upload progress

I would like to add a progress monitor for monitoring file upload progress.

Below is code that does the file upload.  I've also posted the doPost method from the servlet.

I've already added a monitor for other activities such as validating files.  If this were to be similar, I would think I would need to run the executeMethod() function in a SwingWorker thread.

How does the executeMethod() function, or any HttpClient method, return progress to a web start application's ProgressMonitor bar?

I've stumbled upon an example where a ProgressListener is implemented but this seems to be on server-side.  I'm not sure how the JNLP app would get updated with bytes uploaded in that case.

String targetURL = "http://localhost:8080/TestApp/upload
MultipartPostMethod filePost = new MultipartPostMethod(targetURL);

try {
   String zipFilePath = compressor.getCanonicalPath();
   filePost.addParameter(zipFilePath, targetFile);
   HttpClient client = new HttpClient();
   int status = client.executeMethod(filePost);
   if (status == HttpStatus.SC_OK) {
      System.out.println("Upload complete, response=" + filePost.getResponseBodyAsString());
   else {
      System.out.println("Upload failed, response=" + HttpStatus.getStatusText(status));
catch (Exception ex) {
   System.out.println("Error: " + ex.getMessage());
finally {

public void doPost(HttpServletRequest req, HttpServletResponse res) {

   try {

      DiskFileItemFactory factory = new DiskFileItemFactory();
      ServletFileUpload upload = new ServletFileUpload(factory);

      // maximum size that will be stored in memory
      // the location for saving data that is larger than getSizeThreshold()
      //factory.setRepository(new File("/tmp"));

      List items = upload.parseRequest(req);

      String fileName = "";
      long maxSize = 0;

      Iterator iter = items.iterator();
      while (iter.hasNext()) {
         DiskFileItem item = (DiskFileItem);

         // filename on the client
         fileName = item.getName();
         maxSize = item.getSize();

         System.out.println("fileName: " + fileName);
         System.out.println("maxSize: " + maxSize);

         String dest = "/tmp";

         // write the file
         item.write(new File(dest, fileName));
   catch(Exception e) {
         System.out.println("<br>\nError: "+e.getMessage());

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I'm sorry, I'm not sure I understand.

What you are doing - is that you are developing an application
which would be deployed using WebStart ?

Or you are developing a servlet?

If you are developing a application which uses a Webstart - then
it is a regular application running on the client, the progress bar and everything
should work in the same way as with any other client-side

If you are developing the servlet and your activity - uploading of the file
happens to be on the server side, then it is whole different thing,
I'm sure you can do something to keep the client informed
about your progres on the server activity,
but that would be quite different operation altogether.
please clarify
what is it that you need, as you talk about doPost method on one side (which normally
runs on server) and about JNLP on the other side (which is
used to deploy client-side applications).

mock5cAuthor Commented:
I'm developing a webstart application that runs on client-side.  It processes many files.  This webstart then has an upload button to upload the files to a remote server, where the servlet resides.  So I am also developing a servlet.

I already have the webstart and servlet completed, that is the webstart successfully uploads the file to the server (see code I previously posted).  However, I am not sure how to include a progress monitor since the servlet, I assume, would monitor how many bytes are received and report this back to the webstart.

I hope that clarifies my question.

Mick BarryJava DeveloperCommented:
heres a simple progress bar example that may help

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.


Well, of course servlet may know better how many dytes were already uploaded
and it is possible to devise some system to communicate back to client
what is the number of bytes which were uploaded
and then use progressbar code like the
one posted above by objects to show it.

In my opinion, frankly, that would be a little bit of an overkill to set up all this communication
back to client just for the sake of showing the progressbar.
I you are uploading really big files and the speeds of the
upload vary dramaticlly, then it is probably worth
doing. Otherwise I'd rather write some warning to user that
it will take some time, or make an estimate based on
the size of the initial file known to the client
and use this estimate of total time to show the
progress bar. Well, maybe some people will diagree with me, but I'd
think twice before complicating the system and adding
additional communications just because of the progress bar.

mock5cAuthor Commented:
Yes, files are quite large...usually 500MB - 1GB or more.  That is why I'm hoping to show a progress monitor.  I do have 2 progress monitors already used by the webstart but nothing with the servlet reporting current progress.

I'm sure you can do it somehow with servlet/client intercation
What comes to my mind though is to have an RMI server - which would run on
the server and you can reach to it from the client from time to time
and know how much data was already stored on the server

You can probably do something also with WebServices
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.