File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Upload Applet – Servlet and upload cancel function. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Upload Applet – Servlet and upload cancel function." Watch "Upload Applet – Servlet and upload cancel function." New topic
Author

Upload Applet – Servlet and upload cancel function.

P Chaudhari
Greenhorn

Joined: Mar 22, 2004
Posts: 22
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

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39551
    
  27
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.


Ping & DNS - updated with new look and Ping home screen widget
P Chaudhari
Greenhorn

Joined: Mar 22, 2004
Posts: 22
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
Marshal

Joined: Mar 22, 2005
Posts: 39551
    
  27
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

Joined: Mar 22, 2004
Posts: 22
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
Marshal

Joined: Mar 22, 2005
Posts: 39551
    
  27
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.
 
wood burning stoves
 
subject: Upload Applet – Servlet and upload cancel function.
 
Similar Threads
Reading a pdf file from a URL in an applet
Image saving size reduction
file dialog does not close in IE 6
Close Popup Window after download completes
Multiple File Save