Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Upload Client File to Server using Java Servlet

Reply
Thread Tools

Upload Client File to Server using Java Servlet

 
 
hust6
Guest
Posts: n/a
 
      07-24-2006
I have a Java Servlet that produces an HTML form. It asks the user to
input a file using standard input tags:

<input type="file" size=75 name=fileInput>

Once the form is submitted, it calls a different servlet that processes
all the data. The only problem I am having is saving the client's file
on the server. A FileNotFound exception is thrown when the servlet
tries to save the file in a new location. Here is a snippet of my
code:


File newFile = new File(serverFileLoc, fileName);
temp = req.getParameterValues("fileInput");
File origFile = new File(temp);

InputStream ins = new FileInputStream(origFile);
OutputStream outs = new FileOutputStream(newFile);

byte[] buf = new byte[1024];
int len;
while ((len = ins.read(buf)) > 0)
{
outs.write(buf, 0, len);
}
ins.close();
outs.close();


Everything works fine when run locally, but when run from a client
machine, it fails when I create the FileInputStream due to a
FileNotFoundException.

Any ideas?

I would greatly appreciate anyone that could help me solve this
problem. Thanks, Matt

 
Reply With Quote
 
 
 
 
Vincent van Beveren
Guest
Posts: n/a
 
      07-25-2006
> Any ideas?

What package do you use to process the upload? CommonsUpload, COS?
Home-made solution? The default servlet spec does not handle mutlipart
uploads, so you'll have to use a 3rd party library to make it work.

Vincent
 
Reply With Quote
 
 
 
 
jvsoft.org@gmail.com
Guest
Posts: n/a
 
      07-25-2006

Vincent van Beveren wrote:
> > Any ideas?

>
> What package do you use to process the upload? CommonsUpload, COS?
> Home-made solution? The default servlet spec does not handle mutlipart
> uploads, so you'll have to use a 3rd party library to make it work.
>
> Vincent


Just download a copy of 'java upload bean",it's free

<a
href="http://www.developerzone.biz/index.php?option=com_content&task=view&id=151&Item id=36">Java
Tutorials</a>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
File upload from client application (non-form based upload) stuart@microsoft.com Python 1 11-25-2006 12:14 AM
upload a file using servlet anna Java 2 04-06-2006 11:36 AM
JSP/Servlet file upload + tranfer to remote server Edward Java 1 03-20-2006 08:00 AM
Servlet question(Tomcat, web.xml, servlet-class, servlet-name) circuit_breaker Java 2 04-04-2004 03:26 AM
File upload servlet using MultipartRequest - file not created on the server Paul Smith Java 1 11-17-2003 10:24 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57