Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2006

Tip: Looking for answers? Try searching our database.

Upload Client File to Server using Java Servlet

Thread view: 
hust6 - 24 Jul 2006 20:14 GMT
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 - 25 Jul 2006 08:35 GMT
> 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 - 25 Jul 2006 13:25 GMT
> > Any ideas?
>
[quoted text clipped - 3 lines]
>
> 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&Itemi
d=36">Java

Tutorials</a>


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.