Upload Client File to Server using Java Servlet

Discussion in 'Java' started by hust6, Jul 24, 2006.

  1. hust6

    hust6 Guest

    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
     
    hust6, Jul 24, 2006
    #1
    1. Advertising

  2. > 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
     
    Vincent van Beveren, Jul 25, 2006
    #2
    1. Advertising

  3. hust6

    Guest

    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&Itemid=36">Java
    Tutorials</a>
     
    , Jul 25, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul  Smith
    Replies:
    1
    Views:
    3,176
    Paul Smith
    Nov 17, 2003
  2. circuit_breaker
    Replies:
    2
    Views:
    2,045
    Jack Jia
    Apr 4, 2004
  3. anna
    Replies:
    2
    Views:
    4,936
    Stefan Waldmann
    Apr 6, 2006
  4. Chris
    Replies:
    4
    Views:
    596
    Chris
    Feb 2, 2007
  5. Replies:
    1
    Views:
    950
    Gabriel Genellina
    Nov 25, 2006
Loading...

Share This Page