Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Upload Client File to Server using Java Servlet (http://www.velocityreviews.com/forums/t360210-upload-client-file-to-server-using-java-servlet.html)

hust6 07-24-2006 07:14 PM

Upload Client File to Server using Java Servlet
 
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


Vincent van Beveren 07-25-2006 07:35 AM

Re: Upload Client File to Server using Java Servlet
 
> 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

jvsoft.org@gmail.com 07-25-2006 12:25 PM

Re: Upload Client File to Server using Java Servlet
 

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>



All times are GMT. The time now is 11:56 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.