• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Upload Applet – Servlet and upload cancel function.

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Here is a question regarding the applet and servlet communication. Applet is used for uploading the file.

We have a third party applet which converts the office documents into pdf and send to our application (Servlet). This applet provides a window on which it displays the status of upload and cancel button.
1)Problem is if user presses cancel is there a way for Servlet to know that complete file was not uploaded?

Here is my servlet code.

InputStream inputStream = null;
ByteArrayOutputStream out = null;
inputStream = request.getInputStream();
out = new ByteArrayOutputStream();
byte buf[]=new byte[1024];
int len;
while((len=inputStream.read(buf))>0){
out.write(buf,0,len);
}



2) Can applet tell the servlet that file upload was cancelled, if yes how?

Looking forward for your answer and Thanks in advance.

Best Regards
Prasad

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As to #1, I'd use a proper file upload library (like Apache Commons FileUpload) that can handle exceptional conditions.

As to #2, that obviously depends on the applet; if you have access to its source code you could probably add that. If you don't, check its documentation or talk to the developers.
 
P Chaudhari
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the quick response.

1) We cannot change the applet, it is decided that we have to deal with it. So I cannot do anything on that front.

2) do you know how can I pass cancel information from applet to servlet?

Best Regards
Prasad
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As to #1, FileUpload is for use in the servlet, not the applet. Have you read its documentation?

As to #2, remember that we know nothing about the applet, so as I said, that's a question for the developers of that applet.
 
P Chaudhari
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
we are not lucky in the scence that we can put jar at will. But thanks anyways for the usefull info, I can use it in some other project.

Regarding the applet I do not have the access to the applet code. My question was if somebody write an applet, how applet can communicate to the servlet that uploading stream has been cancelled, or all bytes are not transfered?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That depends on how the applet performs the file transfer. If it's an HTTP file upload, then there's no way to communicate that (unless a second call to some other URL is made that communicates this fact). If applet and servlet implements their own special file uploading protocol, then they could of course build in a special notification mechanism.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic